您的位置:首页 > 其它

Complicated Translation 栈的模拟 hoj

2012-06-16 23:40 351 查看
/*对于这道题我表示非常无语。对getchar的用法不熟。

主要是读入字符的问题。然后将每个词入栈。再按顺序弹栈即可。

学会用getchar处理单个字符和对行数的控制。*/

#include <iostream>

#include <stdio.h>
using namespace std;

int main()
{
int n,top;
char a[1100];
char c;
while(scanf("%d",&n)==1&&n)
{
getchar();
for(int i=0; i<n; i++)
{
top=0;
while((c=getchar())!='\n')
{
if(c!=' ')
{
a[top++]=c;
}
else
{
while(top>=1)
{
top--;
printf("%c",a[top]);
}
printf(" ");
}
}
while(top>=1)
{
top--;
printf("%c",a[top]);

}
printf("\n");
}

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: