C/C++ 泛型程式設計vector(排序)
阿新 • • 發佈:2018-12-12
題目描述
對一組輸入的資料(0結束)進行排序輸出。 約定:所有的輸入資料都為正整數,且都不大於100000。
輸入
包括多組測試資料。
每組以0結尾。
輸出
每組輸出1行。輸出排序後的資料(不含0)。
樣例輸入
1 2 3 2 4 0 5 6 2 2 0
樣例輸出
1 2 2 3 4 2 2 5 6
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; int main() { vector<int> v1; vector<int>::iterator iter; int n; while(scanf("%d",&n)!=EOF) { while(n!=0) {v1.push_back(n);scanf("%d",&n);} sort(v1.begin(),v1.end()); for(iter=v1.begin();iter!=v1.end()-1;iter++) { printf("%d ",*iter); } printf("%d\n",*iter); v1.clear(); } return 0; }