uva 484 - The Department of Redundancy Department

已有的数据结构装不下数据,或者不能处理现有的数据,那就必须要思考其他的辅助手段,辅助结构;

 1 #include <cstdio>
 2 #include <map>
 3 #include <vector>
 4 using namespace std;
 5 
 6 vector<int> order;
 7 map<int, int> freq;
 8 
 9 int main()
10 {
11     int n;
12     freq.clear();
13     while(scanf("%d", &n) != EOF)
14     {
15         if(freq.count(n)) freq[n] ++;
16         else freq[n] = 1, order.push_back(n);
17     }
18     for(auto it = order.begin(); it != order.end(); ++ it)
19              printf("%d %d\n", *it, freq[*it]);
20 
21     /*for(int i = 0; i < (int)order.size(); i++)
22         printf("%d %d\n", order[i], freq[order[i]]);*/
23     return 0;
24 }

 

你可能感兴趣的:(uva 484 - The Department of Redundancy Department)