首页 > 其他 > 详细

uva 482 - Permutation Arrays

时间:2016-01-26 23:31:38      阅读:238      评论:0      收藏:0      [点我收藏+]

<int, double> --> <int, string> 从而避免了输出格式;

 1 #include <vector>
 2 #include <string>
 3 #include <iostream>
 4 #include <sstream>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int t, count = 0;
11     string line1, line2;
12     int index;
13     string value;
14     vector<pair<int, string>> store;
15     cin >> t;
16     getchar();
17     while(t--)
18     {
19         getchar();
20         count ++;
21         getline(cin, line1);
22         getline(cin, line2);
23         stringstream ss1(line1), ss2(line2);
24         while(ss1 >> index)
25         {
26             ss2 >> value;
27             store.push_back(pair<int, string>(index, value));
28         }
29         sort(store.begin(), store.end());
30         if(count > 1) cout << endl;
31         for(int i = 0; i < store.size(); i++)
32             cout << store[i].second << endl;
33 
34         store.clear();
35     }
36 
37     return 0;
38 }

 

 1 // 输入输出是怎么回事???
 2 #include <iostream>
 3 #include <string>
 4 #include <sstream>
 5 #include <vector>
 6 #include <map>
 7 
 8 using namespace std;
 9 
10 
11 #define FOI(i, A, B) for(i = A; i <= B; i++)
12 #define FOD(i, A, B) for(i = A; i >= b; i--)
13 
14 string toString(int I)
15 {
16     stringstream ss;
17     string str;
18     ss << I;
19     ss >> str;
20 
21     return str;
22 }
23 
24 int main()
25 {
26     int T;
27     cin >> T;
28     string str, s;
29     while(T--)
30     {
31         getline(cin, str);
32         getline(cin, str);
33         vector<string> ind, val;
34         map<string, string> Map;
35         stringstream ss;
36         getline(cin, str);
37         ss << str;
38         while(ss >> s) ind.push_back(s);
39         int N = ind.size(), i;
40         FOI(i, 0, N-1)
41         {
42             cin >> str;
43             Map[ind[i]] = str;
44         }
45         FOI(i, 0, N-1)
46                 cout << Map[toString(i+1)] << endl;
47         if(T > 0)
48             cout << endl;
49     }
50     return 0;
51 }

 

uva 482 - Permutation Arrays

原文:http://www.cnblogs.com/aze-003/p/5161838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!