zoukankan      html  css  js  c++  java
  • c语言输入一个字符串,统计其字母,数字和其他字符的个数,并以柱状图输出

    #include<stdio.h>
    int main(int arge,char *argv[])
    {
    char ch;
    int alp=0,num=0,oth=0,len,alp_start,num_start,oth_start,i;
    while((ch=getchar())!=-1)
    {
    if(ch>='0'&&ch<='9') num++;
    else if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
    alp++;
    else
    oth++;
    }
    len=alp>num?(alp>oth?alp:oth):(num>oth?num:oth);
    alp_start=len+1-alp;
    num_start=len+1-num;
    oth_start=len+1-oth;
    printf("alp: %d num: %d oth: %d ",alp,num,oth);
    printf("%5s%8s%5s%8s%5s ","alp"," ","num"," ","oth");
    for(i=0;i<len+1;i++)
    {
    if(i==alp_start)
    printf("%3d%2s",alp," ");
    else if(i>alp_start)
    printf("*****");
    else
    printf(" ");
    printf("%8s", " ");
    if(i==num_start)
    printf("%3d%2s",num," ");
    else if(i>num_start)
    printf("*****");
    else
    printf(" ");
    printf("%8s", " ");
    if(i==oth_start)
    printf("%3d%2s",oth," ");
    else if(i>oth_start)
    printf("*****");
    else
    printf(" ");
    printf("%8s", " ");
    printf(" ");
    }
    return 0;
    }

  • 相关阅读:
    外感上吐下泻案
    口唇口腔紅肿案
    柴胡桂枝汤---刘渡舟
    肺结核病人外感咳嗽不止案
    下肢麻木案
    老年人全身皮肤瘙痒案
    眩晕案
    頑固头痛失眠案
    PHP 点阵5*7字体
    PHP workerMan tcp与webSocket 透传互通
  • 原文地址:https://www.cnblogs.com/zhaoheng/p/4324899.html
Copyright © 2011-2022 走看看