我想睡觉


私信TA

用户名:beiqian

访问量:4083

签 名:

等  级
排  名 1644
经  验 2632
参赛次数 0
文章发表 18
年  龄 0
在职情况 学生
学  校 武汉理工大学
专  业

  自我简介:

解题思路:没什么好写的

注意事项:

参考代码:

#include <stdio.h>
#include <string.h>//为了调用strlen()函数

int main(void)
{
    char s[100];                            //定义数组用来储存字符串
    gets(s);                                //输入带有空格的字符串s
    int alp = 0, spa = 0, dig = 0, oth = 0; //字母,空格,数字,其他
    int len = strlen(s);                    //将len定义为s的长度
    for (int i = 0; i < len; ++i)
    {
        if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))//若s[i]在A-Z或者a-z之间
            alp++;
        else if (s[i] == ' ')
            spa++;
        else if (s[i] >= '0' && s[i] <= '9')
            dig++;
        else
            oth++; //这里else if的用法非常重要
    }
    printf("%d\n%d\n%d\n%d", alp, spa, dig, oth);//分别打印出来,记得换行
    return 0;
}


 

0.0分

5 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区