1. 程式人生 > >【HDOJ】1062 Text Reverse

【HDOJ】1062 Text Reverse

main har getline eve names ace pac string ostream

#include<iostream>
#include<string>
using namespace std;
void main()
{
int T;
while (cin>>T)
{
getchar();

for (int i = 0; i < T; i++)
{
string str;
getline(cin, str);
int end = 0,top = 0;
while (str[end] != ‘\0‘)
{
if (str[end]==‘ ‘)
{
for (int i = end-1; i >=top; i--)
{
cout << str[i];
}
top = end + 1;
}
end++;
}
if (str[end]==‘\0‘)
{
for (int i = end; i >=top-1; i--)
{
cout << str[i];
}
}
cout << endl;
}
}
}

【HDOJ】1062 Text Reverse