文章标题
来源:互联网 发布:游戏编程精粹 编辑:程序博客网 时间:2024/06/14 09:34
问题描述
试题编号: 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代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x3f3f3f3f;//1061109567typedef long long LL;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;struct node{ int ip; int num;}a[1010];bool cmp(node x,node y){ if(x.num != y.num) return x.num > y.num; else return x.ip < y.ip;}int main(){ int n; scanf("%d",&n); for(int i=1; i<=1000; i++)//注意这里是1000 { a[i].ip = i; a[i].num = 0; } for(int i=0; i<n; i++) { int x; scanf("%d",&x); a[x].num++; } sort(a,a+1010,cmp);//注意这里是1010 for(int i=0; i<n; i++) { if(a[i].num) { printf("%d %d\n",a[i].ip,a[i].num); } } return 0;}
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- RunLoop应用篇--线程间通信
- Unity后期处理-抗锯齿
- CentOS(Linux)中解决MySQL中文乱码
- 排序
- Ruby On Rails--Action Controller(控制器)
- 文章标题
- 如何在C++代码中访问并调用Java的成员呢?
- LIVE555,RTSP、RTP/RTCP协议介绍
- MFC对话框控件数据提取之DoDataExchange()
- 9个循环9
- oracle awr报告
- SecureCRT防止自动断开
- Android Interface Definition Language (AIDL)详解
- Leetcode no. 40