zoukankan      html  css  js  c++  java
  • SDNU 1185.统计数字(水题)

    Description

    某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*109)。已知不相同的数不超过10000个,现在需要统计这些自然数各自出现的次数,并按照自然数从小到大的顺序输出统计结果。

    Input

    输入包含n+1行;
    第一行是整数n,表示自然数的个数,1<=n<=200000;
    第2~n+1每行一个自然数,每个数均不超过1 500 000 000(1.5*109)。

    Output

    输出包含m行(m为n个自然数中不相同数的个数),按照自然数从小到大的顺序输出。每行输出两个整数,分别是自然数和该数出现的次数,其间用一个空格隔开。

    Sample Input

    8
    2
    4
    2
    4
    5
    100
    2
    100

    Sample Output

    2 3
    4 2
    5 1
    100 2

    Source

    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <map>
    using namespace std;
    #define ll long long
    
    int n;
    ll num[200000+8];
    
    map<ll, int>mp;
    
    struct node
    {
        ll sign;
        int time;
    }r[200000+8];
    
    bool cmp(node a, node b)
    {
        return a.sign<b.sign;
    }
    
    int main()
    {
        scanf("%d", &n);
        ll x;
        for(int i = 0; i<n; i++)
        {
            scanf("%lld", &x);
            if(!mp[x])mp[x] = 1;
            else mp[x]++;
        }
        map<ll, int>::iterator ii;
        int miao = 0;
        for(ii = mp.begin(); ii != mp.end(); ii++)
        {
            r[miao].sign = ii->first;
            r[miao].time = ii->second;
            miao++;
        }
        sort(r, r+miao, cmp);
        for(int i = 0; i<miao; i++)
            printf("%lld %d
    ", r[i].sign, r[i].time);
        return 0;
    }
  • 相关阅读:
    项目中的注意事项
    复合查询
    树型控件的处理(完整版)
    图的存储结构(邻接矩阵)
    图的定义与术语2 数据结构和算法55
    图的存储结构(邻接矩阵)
    赫夫曼编码 数据结构和算法52
    赫夫曼编码 数据结构和算法52
    图的存储结构(邻接矩阵)
    图的定义与术语 数据结构和算法54
  • 原文地址:https://www.cnblogs.com/RootVount/p/10985822.html
Copyright © 2011-2022 走看看