哈理工OJ-2330
Description
ACM twist-toy encountered such a problem in the work, this article, to ensure that this article only lowercase letters
and spaces, please send the articles in each word inverted output, such as “hello world this is an competition”. You
should output “olleh dlrow siht si na noititepmoc”.
Input
A group of data, each line of data input from the lower case letters and spaces of the article, the length of not more than
one thousand
Output
Output a line for each word after the reversal of the article.
Sample Input
hello world this is an competition
Sample Output
olleh dlrow siht si na noititepmoc
题意:
逆序输出字母,看样例
解析:
栈解决一下
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[1111];
while(gets(a))
{
stack<char>sta;
int len=strlen(a);
for(int i=0; i<=len; i++)
{
if(a[i]==' '||i==len)
{
while(!sta.empty())
{
printf("%c",sta.top());
sta.pop();
}
if(i!=len)
printf(" ");
}
else
{
sta.push(a[i]);
}
}
printf("\n");
}
}