PAT_Basic 1009

This time I meet something interesting about coding


First is coding

/*
给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。

输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。

输出格式:每个测试用例的输出占一行,输出倒序后的句子。

输入样例:
Hello World Here I Come
输出样例:
Come I Here World Hello

*/

#include <vector>
#include <string>
#include <iostream>

#include <stack>

using namespace std;

void main(){
	stack<string> stk;
	string tmp_in;

	while (cin>>tmp_in ){
		stk.push(tmp_in);

		
	}

	while (!stk.empty()){
		string tmp_s = stk.top();
		//fflush(stdin);
		cout << tmp_s;
		stk.pop();
	}
	system("pause");
}


Then when we get into the first circle, we type in the strings and try to end the circle.

	while (cin>>tmp_in ){
		stk.push(tmp_in);
	}

Then we find out if we try "Ctrl+C" it can get out directly but failed in the next circle.

When we type "Ctrl+Z" and "Enter", everything is fine.


Interesting.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值