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;
    }

  • 相关阅读:
    SQL学习
    设计模式学习之简单工厂
    c#读写操作3
    SQL存储过程学习
    c# xml的读写
    SQL存储过程实例
    存储过程分页
    搞双显示器
    转:用药的七种心理误区
    lp提了一个非常让偶非常郁闷的要求……
  • 原文地址:https://www.cnblogs.com/zhaoheng/p/4324899.html
Copyright © 2011-2022 走看看