这并不难,但是一定要注意:要用getline!!! 还有一点更重要的:它会先读入字符串长度再读字符串,所以一定要用getchar吃掉回车!!!
#include <iostream>
using namespace std;
int main() {
string s;
int t, l;
cin >> t;
while (t--) {
cin >> l;
getchar();
getline(cin, s);
for (int i = s.size() - 1; i >= 0; i--)if (s[i] != ' ')cout << s[i];
cout << endl;
}
return 0;
}

京公网安备 11010502036488号