当前位置:网站首页>PTA 求一批整数中出现最多的个位数字
PTA 求一批整数中出现最多的个位数字
2022-08-09 10:58:00 【拾荒大妈】
给定一批整数,分析每个整数的每一位数字,求出现次数最多的个位数字。例如给定3个整数1234、2345、3456,其中出现最多次数的数字是3和4,均出现了3次。
输入格式:
输入在第1行中给出正整数N(≤1000),在第二行中给出N个不超过整型范围的非负整数,数字间以*空格分隔。
输出格式:
在一行中按格式“M: n1 n2 …”输出,其中M是最大次数,n1、n2、……为出现次数最多的个位数字,按从小到大的顺序排列。数字间以空格分隔,但末尾不得有多余空格。
输入样例:
3
1234 2345 3456
输出样例:
3: 3 4
思路:
#include<stdio.h>
int main()
{
int n,i,max;
int a[10]={
0};
scanf("%d",&n);
for(i=1;i<=n;i++)//计算各个各位数字出现的次数
{
int c;
scanf("%d",&c);
int number=10;
int b;
do{
b=c%number;
c=c/number;
a[b]++;
}while(c>0);
}
i=1;
max=a[0];
while(i<10)//求最大次数
{
max=max>a[i]?max:a[i];
i++;
}
printf("%d:",max);
for(i=0;i<10;i++)
if(max==a[i])printf(" %d",i);
return 0;
}
边栏推荐
- Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
- uni-app 自带的picker封装一个日期-时间选择器
- 支付宝小程序的接入
- 商业技术解决方案与高阶技术专题 - 数据可视化专题
- Solve 1. tensorflow runs using CPU but not GPU 2. GPU version number in tensorflow environment 3. Correspondence between tensorflow and cuda and cudnn versions 4. Check cuda and cudnn versions
- 数据存储:对dataframe类,使用to_csv()将中文数据写入csv文件
- 基于STM32设计的环境检测设备
- 详细的np.matmul / np.dot / np.multiply / tf.matmul / tf.multiply / *
- tensorflow实现线性方程的参数调整
- cesium加载地图
猜你喜欢
随机推荐
综述文章的写法
性能测试(03)-JDBC Request
乘积量化(PQ)
情感分析SowNLP词库
Since I use the HiFlow scene connector, I don't have to worry about becoming a "dropper" anymore
cnn的输入输出
The complete grammar of CSDN's markdown editor
使用pip成功安装某个库,但pycharm中找不到,此问题的解决方案
多商户商城系统功能拆解26讲-平台端分销设置
torch.cat()函数的官方解释,详解以及例子
Qt获取EXE可执行文件的上一级目录下的文件
Official explanation, detailed explanation and example of torch.cat() function
jmeter BeanShell 后置处理器
[华为云在线课程][SQL语法分类][数据操作][学习笔记]
最长回文子串
STM32使用静态队列保存数据
MySQL外键在数据库中的作用
golang源代码阅读,sync系列-Map
activemq 消息持久化
tensorflow和numpy对应的版本,报FutureWarning: Passing (type, 1) or ‘1type‘ as a synonym of type is deprecate