tzu230341315


私信TA

用户名:dotcpp0736098

访问量:1163

签 名:

等  级
排  名 4217
经  验 1709
参赛次数 2
文章发表 21
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:



参考代码:

#include <stdio.h>

int

main(void)

{

    int letter = 0, number = 0, space = 0, other = 0;

    char ch;

     

    while( (ch = getchar()) != '\n'){     /*这里的‘\n’不能换成EOF,要不就把输入的换行符输入进来当成其他字符处理,

                                            因此其他字符的数量将比题目所给的数量多一*/

        if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))

            letter += 1;   //letter表示字母数量

        else

        if (ch == ' ')

                space += 1;  //空格数量

            else

            if (ch >= '0' && ch <= '9')

                number += 1; //数字数量

                else

                other += 1;  //其他字符数量

    }

    printf("%d %d %d %d", letter, number, space, other);

     

    return 0;

}


 

0.0分

1 人评分

  评论区

  • «
  • »