#include <iostream>
#include <istream>
#include <ostream>
#include <string>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(NULL);
// mainString --- maStr
string maStr;
cin >> maStr;
int m;
cin >> m;
int size = maStr.size();
while(m--)
{
int ai;
cin >> ai;
// subsetOfMainString --- subMaStt
string subMaStr;
for (int i = ai - 1; i <= size - ai; ++i)
subMaStr[(size - ai - i)] = maStr[i];
for (int i = ai - 1; i <= size - ai; ++i)
maStr[i] = subMaStr[i - ai + 1];
}
cout << maStr << '\n';
}
The above code is working fine and even able to pass the test in my pc but still why isn't it working here. Help !
Most probbably this "i <= size — ai" should be "i <= size — ai-1" or "<=" should be "<".