hdoj-1106-排序(stringstream)

题目链接

 1 /*
 2     Name:
 3     Copyright:
 4     Author:
 5     Date: 2018/5/2 20:56:53
 6     Description:
 7 */
 8 #include <iostream>
 9 #include <cstdio>
10 #include <cstring>
11 #include <algorithm>
12 #include <sstream>
13 #include <vector>
14 using namespace std;
15 int arr[30];
16 int main()
17 {
18     string str;
19     while (cin>>str) {
20         int i = 0;
21         while (str[i] == '0') i++;
22         if (i > 1) str = str.substr(i-1);
23         int pos = 0;
24         while ( (pos = str.find('5')) != -1) {
25             str.replace(pos, 1, " ");
26         }
27         stringstream ss;
28         ss<<str;
29         vector<int> vec;
30         while (ss>>i) vec.push_back(i);
31         sort(vec.begin(), vec.end());
32         cout<<vec[0];
33         for (int i=1; i<vec.size(); i++) {
34             cout<<" "<<vec[i];
35         }
36         cout<<endl;
37     }
38     return 0;
39 }

猜你喜欢

转载自www.cnblogs.com/evidd/p/8982592.html