题目
解法
//翻转字符串
#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
using namespace std;
int main()
{
int n;
cin >>n;
getchar();
while(n--){
stack<char>s;
char ch;
while(true){
ch=getchar();
if(ch==' '||ch=='\n'||ch==EOF/*表示输入结束,这里容易忽略*/){
while(!s.empty()){
cout << s.top();
s.pop();
}
if(ch==' '){
cout << ch;
}else{
break;
}
}else{
s.push(ch);
}
}
cout << endl;
}
system("pause");
return 0;
}
倒是没啥坑,就是注意换行符的读入,不过下面也有hint,注意看就行了。