zoukankan      html  css  js  c++  java
  • c语言 8-10

    1、

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, ch;
        int cnt[10] = {};
        
        while((ch = getchar()) != EOF)
        {
            if(ch > '0' && ch < '9')
            {
                cnt[ch - '0']++;
            }
        }
        
        puts("show the times.");
        for(i = 0; i < 10; i++)
        {
            printf("'%d' : ", i);
            for(j = 0; j < cnt[i]; j++)
            {
                putchar('*');
            }
            putchar('
    ');
        }
        
        return 0;
    }

    2、

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, ch;
        int cnt[10] = {};
        
        while((ch = getchar()) != EOF)
        {
            if(ch >= '0' && ch <= '9')
            {
                cnt[ch - '0']++;
            }
        }
        
        int max = cnt[0];
        for(i = 0; i < 10; i++)
        {
            if(cnt[i] > max)
            {
                max = cnt[i];
            }
        }
        
        for(i = max; i > 0; i--)
        {
            for(j = 0; j < 10; j++)
            {
                if(cnt[j] >= i)
                {
                    printf("   *");
                }
                else
                {
                    printf("    ");
                }
            }
            putchar('
    ');
        }
        puts("==============================================");
        for(i = 0; i < 10; i++)
        {
            printf("%4d", i);
        }
        putchar('
    ');
        return 0;
    }

    #include <stdio.h>
    
    int main(void)
    {
        int i, j, ch;
        int cnt[10] = {};
        
        while((ch = getchar()) != EOF)
        {
            if(ch >= '0' && ch <= '9')
            {
                cnt[ch - '0']++;
            }
        }
        
        int max = cnt[0];
        for(i = 0; i < 10; i++)
        {
            if(cnt[i] > max)
            {
                max = cnt[i];
            }
        }
        
        for(i = max; i > 0; i--)
        {
            for(j = 0; j < 10; j++)
            {
                if(cnt[j] >= i)
                {
                    printf("  *  ");
                }
                else
                {
                    printf("     ");
                }
            }
            putchar('
    ');
        }
        puts("=================================================");
        for(i = 0; i < 10; i++)
        {
            printf(" '%d' ", i);
        }
        putchar('
    ');
        return 0;
    }

  • 相关阅读:
    springboot(十二)-分布式锁(redis)
    springboot(十一)-为什么要用springboot
    HashMap和HashTable区别
    ArrayList和LinkedList区别
    springcloud(三)-Eureka
    springboot(十)-监控应用
    springboot(九)-log配置
    springcloud(二)-最简单的实战
    rest版的webservice
    sqlite与android交互 (封装)
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14803847.html
Copyright © 2011-2022 走看看