zoukankan      html  css  js  c++  java
  • 入门模拟——(字符串处理)B1021个位数统计

    第二次:

    #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
    ",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
    ");
        }
        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
    ",i,temp[i]);
            }
        }
        system("pause");
        return 0;
    } 
  • 相关阅读:
    WKT转换工具terraformers
    关于微信公众号投票结果的通告
    个人博客03
    个人博客02
    个人博客01
    四则运算2
    学习进度条
    构建之法阅读笔记01
    错误随笔
    软件工程概论第一节
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12129611.html
Copyright © 2011-2022 走看看