your code can`t process last input.sunnycare wrote:I have searched all sample inputs on board, and all are right...
Why judge still give me a WA instead of a AC![]()
here is my code:Code: Select all
#include <iostream> #include <string> using namespace std; string word; char ch; void reverseOut(string &s) { long i=s.length()-1; while(i>=0) { cout<<s[i]; i--; } } void main() { while(cin.get(ch)) { if(ch==' '||ch=='\n') { reverseOut(word); cout<<ch; word=""; } else { word+=ch; } } }
Waiting your help!!![/code]
if last input doesn`t have ' 'or '\n',
the output must be wrong.
Code: Select all
void main()
{
while(cin.get(ch))
{
if(ch==' '||ch=='\n')
{
reverseOut(word);
cout<<ch;
word="";
}
else
{
word+=ch;
}
}
reverseOUt(word);//<----I think that you loss this.
}