tuquy795
Rating
-
Bài tập
0
Điểm
0
Rating #
-
Điểm #
28310
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;
}