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 <iostream>
#include <map>
#include <vector>

using namespace std;

int main()
{
    map<int, int> m;
    vector<int> 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;
}




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值