当前位置:网站首页>洛谷一P1097 [NOIP2007 提高组] 统计数字
洛谷一P1097 [NOIP2007 提高组] 统计数字
2022-07-30 05:46:00 【缘聚654】
题目描述
某次科研调查时得到了nn个自然数,每个数均不超过1500000000(1.5 \times 10^9)1500000000(1.5×109)。已知不相同的数不超过1000010000个,现在需要统计这些自然数各自出现的次数,并按照自然数从小到大的顺序输出统计结果。
输入格式
共n+1n+1行。
第一行是整数nn,表示自然数的个数;
第22至n+1n+1每行一个自然数。
输出格式
共mm行(mm为nn个自然数中不相同数的个数),按照自然数从小到大的顺序输出。
每行输出22个整数,分别是自然数和该数出现的次数,其间用一个空格隔开。
输入输出样例
输入 #1复制
8 2 4 2 4 5 100 2 100
输出 #1复制
2 3 4 2 5 1 100 2
说明/提示
40\%40%的数据满足:1 \le n \le 10001≤n≤1000
80\%80%的数据满足:1 \le n \le 500001≤n≤50000
100\%100%的数据满足:1 \le n \le 2000001≤n≤200000,每个数均不超过1500 000 000(1.5 \times 109)1500000000(1.5×109)
思路:将数据放入到数组中,并对其进行升序排序,接着通过前后数字对比统计相同数的个数并输出,代码如下
#include<stdio.h>
void paixu( int b[],int s)
{
int i,j,t;
for(i=0;i<s-1;i++)
for(j=i+1;j<s;j++)
if(b[i]>b[j])
{ t=b[i];b[i]=b[j];b[j]=t;}
}
int main()
{
int n,i,j;
scanf("%d",&n);
int a[n];
for(j=0;j<n;j++)
scanf("%d",&a[j]);
paixu(a,n);
j=1;
for(i=0;i<n;i++)
{
if(a[i]==a[i+1])
j++;
else
{
printf("%d %d\n",a[i],j);
j=1;
}
}
}才疏学浅,当数据过多时会出现超时的现象,日后将会加以改进。
边栏推荐
- xxx is not in the sudoers file.This incident will be reported错误
- this是什么(你不知道的JS)
- QT连载1:readyRead()函数,数据分包不完整解决办法
- 多层板的层数,为啥选项都是偶数?就不能选奇数?
- FPGA parsing B code----serial 2
- Explore the efficiency of make_shared
- Three working modes of CPU: real mode, protected mode, long mode
- 高效插入map数据
- 干货 | 什么是FOC?一文带你看BLDC电机驱动芯片及解决方案
- Kunlun state screen production (serial 3) - based article (button serial port to send)
猜你喜欢

二进制到汇编:进制,原码反码补码,位运算,通用寄存器,内存一套打通

探究make_shared效率
![[Quick MSP430f149] Notes on learning MSP430f149 during the game](/img/06/741c609b24be007718091b8348666c.png)
[Quick MSP430f149] Notes on learning MSP430f149 during the game

vscode set sublime theme

【部分项目展示】

高交会重要活动之一|2020中国硬件创新大赛全国总决赛

VSCode hides the left activity bar

OpenLayers 初学者指南,源码测试可用

Kunlun state screen production (serial 3) - based article (button serial port to send)

Kunlun On-state Screen Production (serial 1)---Contact
随机推荐
QT串口和CAN数据动态实时显示最后日志
写在公众号之前——QT,ARM,DSP,单片机,电力电子与传动!
vscode set sublime theme
重磅揭晓!第十四届深创赛福田预选赛区暨华秋第八届硬创大赛华南分赛区晋
自定义类加载器
Antd 树拖拽一些细节,官网没有,摸坑篇
How to open terminal in VsCode
Delete all files containing a keyword in the current path
SSH-RSA密钥
openssl 1.1.1 compile statement
多层板的层数,为啥选项都是偶数?就不能选奇数?
[Quick MSP430f149] Notes on learning MSP430f149 during the game
Explore the efficiency of make_shared
VSCode隐藏左边活动栏
The IEEE under the specified journal search related papers
Written before the official account - QT, ARM, DSP, microcontroller, power electronics and transmission!
This beta version of Typora is expired, please download and install a newer; workaround
关于报错vscode
闭包和作用域(你不知道的JS自用笔记)
华秋第八届硬创赛与安创加速器达成战略合作,助力硬科技项目成长