林惜城


私信TA

用户名:reminder

访问量:27581

签 名:

等  级
排  名 94
经  验 8487
参赛次数 0
文章发表 95
年  龄 0
在职情况 学生
学  校 西安电子科技大学
专  业

  自我简介:

哈姆


解题思路:

和 1012: [编程入门]字符串分类统计  一模一样,区别只是本题要写子函数。

1012题链接:https://blog.dotcpp.com/a/84267


注意事项:

maxSize一开始设50小了,设成100通过了。


参考代码:

#include <iostream>
#include <cstring>

using namespace std;

const int maxSize = 100; //字符串最大长度
void printEachType(char *str);
int main()
{
    char str[maxSize];
    cin.getline(str, maxSize); //读输入
    printEachType(str);
    return 0;
}
void printEachType(char *str){
    int letter = 0;
    int number = 0;
    int space = 0;
    int other = 0;
    for(int i = 0; i < strlen(str); i++){
        if((str[i] > 64 && str[i] < 91) || (str[i] > 96 && str[i] < 123)){
            letter++;
        }
        else if(str[i] > 47 && str[i] < 58){
            number++;
        }
        else if(str[i] == 32){
            space++;
        }
        else{
            other++;
        }
    }
    cout << letter << " " << number << " " << space << " " << other << endl;
}


 

0.0分

17 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区