当前位置:网站首页>B1021 个位数统计
B1021 个位数统计
2022-07-27 05:01:00 【叶辰 .】
1021 个位数统计 (15 分)
给定一个 k 位整数 N,满足下方公式:
请编写程序统计每种不同的个位数字出现的次数。例如:给定 N=100311,则有 2 个 0,3 个 1,和 1 个 3。
输入格式:
每个输入包含 1 个测试用例,即一个不超过 1000 位的正整数 N。
输出格式:
对 N 中每一种不同的个位数字,以 D:M 的格式在一行中输出该位数字 D 及其在 N 中出现的次数 M。要求按 D 的升序输出。
输入样例
100311
输出样例
0:2
1:3
3:1
题目分析:
- 使用string来读入数字字符
- 记数数组flag
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int flag[10]={0};
getline(cin,s);
for(int i=0;i<s.size();i++){
int number=s[i]-'0';
flag[number]++;
}
for(int i=0;i<=9;i++){
if(flag[i]){
cout<<i<<":"<<flag[i]<<endl;
}
}
return 0;
}
边栏推荐
- Raspberry pie output PWM wave to drive the steering gear
- 写代码涉及到的斜杠/和反斜杠\
- JVM上篇:内存与垃圾回收篇三--运行时数据区-概述及线程
- Raspberry pie RTMP streaming local camera image
- I've heard the most self disciplined sentence: those I can't say are silent
- JVM上篇:内存与垃圾回收篇十--运行时数据区-直接内存
- Sunyanfang, co-founder of WeiMiao: take compliance as the first essence and become the "regular army" of financial and business education
- Mysql表的约束
- Use of file i/o in C
- Final Cut Pro Chinese tutorial (2) understanding of material window
猜你喜欢

Introduction to Web Framework

How to store the startprocessinstancebykey method in acticiti in the variable table

Acticiti中startProcessInstanceByKey方法在variable表中的如何存储

Mysql表的约束

Sunyanfang, co-founder of WeiMiao: take compliance as the first essence and become the "regular army" of financial and business education

对话框简介

JVM Part 1: memory and garbage collection -- runtime data area 4 - program counter

OFDM 16 lecture 2-ofdm and the DFT

ssm框架整合

What about PS too laggy? A few steps to help you solve the problem
随机推荐
What is the future development direction of software testing engineers?
事件总结-常用总结
How to sinicize the JMeter interface?
Card drawing program simulation
Read write separation and master-slave synchronization
JVM上篇:内存与垃圾回收篇十--运行时数据区-直接内存
文件处理(IO)
精选用户故事|洞态在聚水潭的误报率几乎为0,如何做到?
Quoted popular explanation
Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes
[acwing] solution to the 61st weekly match
测试基础5
Jmeter 界面如何汉化?
支付流程如何测试?
How to copy Photoshop layers to other documents
Sunset red warm tone tinting filter LUTS preset sunset LUTS 1
OFDM 16 lecture 2-ofdm and the DFT
Another skill is to earn 30000 yuan a month+
34. 分析flexible.js
写代码涉及到的斜杠/和反斜杠\