您的位置:首页 > 其它

哈理工OJ-2330-Final Ugly English【栈】

2018-02-08 19:32 405 查看
哈理工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");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  哈理工