这个题
用这个代码就能过
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,t="";
queue<string>q;
while(cin>>s)q.push(s);
while(q.size()){
t=q.front();
q.pop();
reverse(t.begin(),t.end());
cout<<t<<endl;
}
}
但是用下面这个就wa
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,t="";
getline(cin,s);
queue<string>q;
for(int i=0;i<s.size();i++){
if(s[i]==' '){
q.push(t);
t="";
}else if(i+1==s.size()){
t=t+s[i];
q.push(t);
}else t=t+s[i];
}
while(q.size()){
t=q.front();
q.pop();
reverse(t.begin(),t.end());
cout<<t<<endl;
}
}
why?getline有什么坑?