zoukankan      html  css  js  c++  java
  • CCF-CSP201503-2 数字排序

    题目链接

    问题描述

    试题编号: 201503-2
    试题名称: 数字排序
    时间限制: 1.0s
    内存限制: 256.0MB
    问题描述:

    问题描述

      给定n个整数,请统计出每个整数出现的次数,按出现次数从多到少的顺序输出。

    输入格式

      输入的第一行包含一个整数n,表示给定数字的个数。
      第二行包含n个整数,相邻的整数之间用一个空格分隔,表示所给定的整数。

    输出格式

      输出多行,每行包含两个整数,分别表示一个给定的整数和它出现的次数。按出现次数递减的顺序输出。如果两个整数出现的次数一样多,则先输出值较小的,然后输出值较大的。

    样例输入

    12
    5 2 3 3 1 3 4 2 5 2 3 5

    样例输出

    3 4
    2 3
    5 3
    1 1
    4 1

    评测用例规模与约定

      1 ≤ n ≤ 1000,给出的数都是不超过1000的非负整数。

    AC代码:

     1 #include<iostream>
     2 #include<sstream>
     3 #include<algorithm>
     4 #include<string>
     5 #include<cstring>
     6 #include<iomanip>
     7 #include<vector>
     8 #include<cmath>
     9 #include<ctime>
    10 #include<stack>
    11 #include<queue>
    12 #include<map>
    13 #define e 2.71828182
    14 #define Pi 3.141592654
    15 using namespace std;
    16 struct node
    17 {
    18     int num;
    19     int time;
    20     node(int nu=0,int ti=0)
    21     {
    22         num=nu;time=ti;
    23     }
    24     friend bool operator < (node& a,node& b)
    25     {
    26         if(a.time!=b.time) return a.time>b.time;
    27         else return a.num<b.num;
    28     }
    29 }fig[1010];
    30 int main()
    31 {
    32     int n;
    33     cin>>n; 
    34     
    35         int num,count=1;
    36         for(int i=1;i<=n;i++)
    37         {
    38             cin>>num;
    39             int j=1;
    40             for(;j<count;j++)
    41             {
    42               if(num==fig[j].num) 
    43               {
    44                   fig[j].time++;break;
    45               }
    46         }
    47         if(j==count) fig[count++].num=num,fig[count-1].time++;
    48     }
    49     sort(fig+1,fig+count);
    50     for(int i=1;i<count;i++)
    51     cout<<fig[i].num<<' '<<fig[i].time<<endl;
    52 }
    View Code
  • 相关阅读:
    固定sql语句传参批量查询数据库脚本
    超多行数据纵向编辑
    takes 3 positional arguments but 4 were given错误
    使用PMD进行代码审查(转)
    WebADI应用到Office 2016 64-bit
    SVN 提交代码时强制加入注释内容
    DOCKER初体验
    "make_path" is not exported by the File::Path modul
    perl 调用shell脚本
    scp 上传文件到多个服务器节点
  • 原文地址:https://www.cnblogs.com/wangzhebufangqi/p/12796122.html
Copyright © 2011-2022 走看看