哈理工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");
}
}
本文介绍了一个简单的字符串处理问题,即如何将输入的一行由小写字母和空格组成的文本中的每个单词进行逆序输出。通过使用栈的数据结构,可以有效地解决这一问题。

被折叠的 条评论
为什么被折叠?



