版权信息 转载请注明出处 [ametake版权所有]http://blog.youkuaiyun.com/ametake欢迎来看
题目很简单,本质还是练习一下vector
题目描述 Description
给定一个正整数序列,请将这个序列倒置后输出
输入描述 Input Description
输入包括一行,即给定的正整数序列,正整数之间用空格隔开。
输出描述 Output Description
输出包括一行,即倒置后的序列。
样例输入 Sample Input
1 3 5 2 4
样例输出 Sample Output
4 2 5 3 1
数据范围及提示 Data Size & Hint
保证序列的长度小于10000,每个数小于32767。
这个本来还是TY君教我的呢 如今TY君不知何处去了 还是有些想念的
我们以为会后继无人,但是明天早上就会有弟弟妹妹来了 欢迎他们 希望他们也能继承我们的衣钵好好学 争取出个进队爷?【虽然希望渺茫
废话太多了,上代码
//codevs3393 序列倒置 vector练习
//这还是TY君教的呢~
//copyright by ametake
#include
#include
using namespace std;
vector s;
int i;
int main(){
while (cin>>i)
{
s.push_back(i);
}
for (int i=s.size()-1;i>=0;i--) printf("%d ",s[i]);
printf("\n");
return 0;
}
顺带放上很久之前TY君的字符串反转代码
#include<iostream>
#include<vector>
#include<string>
using namespace std;
main(){
string str;
vector<string>a;//¿ªÒ»¸ö×Ö·û´®µÄÊý×飬Ãû×Ö½Ða
while(cin>>str){//if str exist return 1 else return 0
a.push_back(str);//if it's not the first put it behind the last
}
for(int i=a.size()-1;i>=0;--i)cout<<a[i]<<" ";//output in the opposite way
}
——将子无怒,秋以为期