• LQDOJ
  • Trang chủ
  • Bài tập
  • Bài nộp
  • Thành viên
  • Kỳ thi
  • Nhóm
  • Giới thiệu
    • Máy chấm
    • Khóa học
    • Đề xuất ý tưởng
    • Đề xuất bài tập
    • Tools
    • Báo cáo tiêu cực
    • Báo cáo lỗi

Tiếng Việt

Tiếng Việt
English

Đăng nhập

Đăng ký

tuquy795

  • Giới thiệu
  • Bài tập
  • Bài nộp

Rating
-
Bài tập
0
Điểm
0
Rating #
-
Điểm #
29163

Giới thiệu

include <iostream>

include <fstream>

include <string>

using namespace std;

string rotateLeft(const string &s, int times) {
int n = s.length();
if (n == 0) return s;
times = times % n;
return s.substr(times) + s.substr(0, times);
}

string rotateRight(const string &s, int times) {
int n = s.length();
if (n == 0) return s;
times = times % n;
return s.substr(n - times) + s.substr(0, n - times);
}

int main() {
ifstream infile("ROBOT.INP");
ofstream outfile("ROBOT.OUT");

string S, A;
getline(infile, S);
getline(infile, A);

int count_L = 0, count_R = 0;
for (char c : A) {
    if (c == 'L') count_L++;
    else if (c == 'R') count_R++;
}

int net = count_R - count_L;


string result;
if (net > 0) {
    result = rotateRight(S, net);
} else if (net < 0) {
    result = rotateLeft(S, -net);
} else {
    result = S; 
}


outfile << result << endl;

infile.close();
outfile.close();

return 0;

}


«    »
Thứ 2
Thứ 3
Thứ 4
Thứ 5
Thứ 6
Thứ 7
CN
Ít
Nhiều

proudly powered by DMOJ| developed by LQDJudge team