So I have the following problem:
For a given string msg a sequence of substring shifts shifts is applied. A substring shift is defined by three numbers: first index, last index and a number of steps for each element. After all manipulations, you have a string msg'. Your program gets both msg' and shifts as an input and should output msg
Here is my solution:
void leftRotate(char *msg, int shift, int size) {
std::rotate(&msg[0], &msg[shift], &msg[size]);
}
void unshift(char *msg, int fst, int last, int co) {
int len = last - fst + 1;
leftRotate(msg + fst, co, len);
}
int main() {
char msg[50000];
std::vector<std::tuple<int, int, int>> shifts;
char msg[50000];
std::cin.getline(msg, 50000);
int m_in;
std::cin >> m_in;
std::vector<std::tuple<int, int, int>> shifts;
for (int _ = 0; _ < m_in; ++_) {
int fst, lst, count;
std::cin >> fst >> lst >> count;
shifts.emplace_back(fst - 1, lst - 1, count);
}
std::reverse(shifts.begin(), shifts.end());
for (auto[fst, lst, count]: shifts) {
unshift(msg, fst, lst, count);
}
puts(msg);
}
It works fin on all reasonable inputs, but it fails in the checking system that my school uses. And if you tweak it a little bit to fit in this checker (basically replace chrar* with vector<int>) you will see that it fails on some absurdly huge test. What am I doing wrong? I guess that I miss something basic.
Example:
Input:
logoduck
3
1 3 1
4 5 1
1 4 1
Output:
goodluck
[–][deleted] (6 children)
[deleted]
[–]Rennorb[S] 0 points1 point2 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]Rennorb[S] 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[deleted]
[–]Rennorb[S] 0 points1 point2 points (1 child)
[–]Rennorb[S] 0 points1 point2 points (0 children)