开始我真的单纯的去文本翻转了....然后没有意外的TLE
后面发现.....直接倒序输出即可....
Presentation Error 代码:(:逃 懒得找了格式问题
#include<iostream>
#include<string>
#pragma warning(disable:4996)
using namespace std;
int main(void) {
int N,index,l;
char c;
cin >> N;
getchar();
string t;
while (N--) {
index = -1;
getline(cin, t);
l= t.length();
for (int i = 0; i < l; i++) {
if (t[i] == ' ') {
for (int j =i-1; j >index; j--) {
printf("%c", t[j]);
}
printf(" ");
index = i;
}
else if (i == l - 1) {
for (int j = i; j >index; j--) {
printf("%c", t[j]);
}
printf("\n");
}
}
}
system("pause");
return 0;
}
TLE代码:
#include<iostream>
# include<string>
#include<algorithm>
using namespace std;
int main(void) {
int N; cin >> N;
char c;
string t, res = "";
while (N--) {
while (1) {
cin >> t;
c = getchar();//吃空格符和换行符
reverse(t.begin(), t.end());
res += t;
if (c == ' ') res += " ";
if (c == '\n') break;
}
if(N)
res += '\n';
}
cout << res << endl;
system("pause");
return 0;
}