UVA484 The Department of Redundancy Department【Ad Hoc+map+vector】

Write a program that will remove all duplicates from a sequence of integers and print the list of uniqueintegers occuring in the input sequence, along with the number of occurences of each.

Input

The input file will contain a sequence of integers (positive, negative, and/or zero). The input file maybe arbitrarily long.

Output

The output for this program will be a sequence of ordered pairs, separated by newlines. The firstelement of the pair must be an integer from the input file. The second element must be the numberof times that that particular integer appeared in the input file. The elements in each pair are to beseparated by space characters. The integers are to appear in the order in which they were containedin the input file.

Sample Input

3 1 2 2 1 3 5 3 3 2

Sample Output

3 4

1 2

2 3

5 1


问题链接:UVA484 The Department of Redundancy Department

问题简述:统计数的出现次数,按数出现的顺序输出那个数和出现的次数。

问题分析:(略)

程序说明

  使用map可以简单第进行统计,但是顺序无法保证。

  使用vector来存储数出现的顺序。

题记:(略)

参考链接:(略)


AC的C++语言程序如下:

/* UVA484 The Department of Redundancy Department */

#include 
#include 
#include 

using namespace std;

int main()
{
    map m;
    vector v;
    int a;

    while(cin >> a) {
        if(m.find(a) == m.end()) {
            m.insert(make_pair(a, 1));
            v.push_back(a);
        } else
            m[a]++;
    }

    for(int i=0; i<(int)v.size(); i++)
        cout << v[i] << " " << m[v[i]] << endl;

    return 0;
}




你可能感兴趣的:(#,ICPC-备用二,#,ICPC-Ad,Hoc,#,ICPC-STL标准模板库,#,ICPC-UVA,UVA484,The,Department,of,Redundancy,D,The,Department,of,Redundancy,D)