So, I was solving a string-related problem. Judge link: www.urionlinejudge.com.br/judge/en/problems/view/1235
Problem Description:
Your printer has been infected by a virus and is printing gibberish. After staring at several printed pages for a while, you realize that it is printing every line inside-out. In other words, the left half of each line is being printed starting in the middle of the page and proceeding out toward the left margin. Similarly, the right half of each line is being printed starting at the right margin and proceeding in toward the middle of the page.
For example, the line: THIS LINE IS GIBBERISH is being printed as: I ENIL SIHTHSIREBBIG S
In the same way, the line " MANGOS " is being printed as "NAM SOG".Your task is to unscramble a String line from its printed form back into its original order. You can assume that line contains an even number of characters.
I tested many different test cases, and the solutions were exactly as expected. But whenever I tried to submit, the judge saying Wrong Answer 100%.
Is there anything wrong with my code? Or is it my compiler that has issues?
#include <bits/stdc++.h>
using namespace std;
int main() {
int t; cin >> t;
cin >> ws;
while(t--)
{
string str;
string str1, str2;
getline(cin, str);
int n = str.length();
str1 = str.substr(0, n/2);
str2 = str.substr(n/2, n/2);
reverse(str1.begin(), str1.end());
reverse(str2.begin(), str2.end());
cout << str1 << str2 << endl;
}
return 0;
}