首页 > 其他 > 详细

入门模拟——(字符串处理)B1021个位数统计

时间:2020-01-01 20:15:59      阅读:88      评论:0      收藏:0      [点我收藏+]

第二次:

技术分享图片

 

 

#include <bits/stdc++.h>
#include <math.h>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAX_LEN = 100005;
//const int MAX_D = 31;
int main(){
    char str[MAX_LEN];
    int result[10] ={0};
    //gets(str);
    cin>>str;
    int len = strlen(str);
    for(int i =0;i<len;++i){
        result[str[i]-0]++;
    }
    for(int i = 0;i<10;++i){
        if(result[i]!=0){
            printf("%d:%d\n",i,result[i]);
        }
    }
    system("pause");
    return 0;
} 

 

第一次:

技术分享图片

 

 

#include <bits/stdc++.h>
#include<math.h>
using namespace std;
const int MAX_LEN = 100005;
//const int MAX_D = 31;
int main(){
    int n;
    cin>>n;
    int digit = 0;
    int temp[10]={0};
    if(n == 0){
        printf("0:1\n");
    }
    while(n != 0){
        int d =  n % 10;
        temp[d]++;
        n = n/10;
    }
    for(int i=0;i<=9;++i){
        if(temp[i]!=0){
            printf("%d:%d\n",i,temp[i]);
        }
    }
    system("pause");
    return 0;
} 

入门模拟——(字符串处理)B1021个位数统计

原文:https://www.cnblogs.com/JasonPeng1/p/12129611.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!