当前位置:网站首页>B1021 single digit statistics
B1021 single digit statistics
2022-07-27 05:20:00 【Ye Chen】
1021 Single digit statistics (15 branch )
Given a k An integer N, Satisfy the following formula :
Please write a program to count the number of times each different digit number appears . for example : Given N=100311, Then there are 2 individual 0,3 individual 1, and 1 individual 3.
Input format :
Each input contains 1 Test cases , I.e. no more than one 1000 Bit positive integer N.
Output format :
Yes N Each different digit in , With D:M Output the digit in one line D And in N Is the number of times M. Required press D Ascending output of .
sample input
100311
sample output
0:2
1:3
3:1
Topic analysis :
- Use string To read numeric characters
- Count array flag
The code is as follows :
#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;
}
边栏推荐
猜你喜欢

JVM Part 1: memory and garbage collection part 12 -- stringtable

Alphabetic order problem

Could not autowire.No beans of ‘userMapper‘ type found.

Constraints of MySQL table

Derivation and explanation of PBR physical illumination calculation formula

JVM Part 1: memory and garbage collection part 5 -- runtime data area virtual machine stack

JVM上篇:内存与垃圾回收篇二--类加载子系统

How idea creates a groovy project (explain in detail with pictures and texts)

The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay

数据库设计——关系数据理论(超详细)
随机推荐
34. 分析flexible.js
JVM Part 1: memory and garbage collection part 9 - runtime data area - object instantiation, memory layout and access location
精选用户故事|洞态在聚水潭的误报率几乎为0,如何做到?
Event
弹球小游戏
Acticiti中startProcessInstanceByKey方法在variable表中的如何存储
[Niuke discussion area] Chapter 7: building safe and efficient enterprise services
Complete Binary Tree
Raspberry pie output PWM wave to drive the steering gear
Two dimensional array summation exercise
Acceptance and neglect of events
What is the future development direction of software testing engineers?
Select user stories | the false positive rate of hole state in jushuitan is almost 0. How to do this?
C中文件I/O的使用
MySQL storage engine and its differences
Domestic mainstream ERP software market
Bean的生命周期&&依赖注入*依赖自动装配
Tcp server是如何一个端口处理多个客户端连接的(一对一还是一对多)
[CSAPP] Application of bit vectors | encoding and byte ordering
JVM Part 1: memory and garbage collection part 10 - runtime data area - direct memory