题解 | #统计字符串中各类型字符的个数#

统计字符串中各类型字符的个数

https://www.nowcoder.com/practice/d5b44c494ed24d8ebb10607c469280e3

#include <iostream>
#include <map>
using namespace std;

int main() {
    char str[100] = { 0 };
    cin.getline(str, size(str));
    map<string, int> maps;
    maps.insert(pair<string, int>("letter", 0));
    maps.insert(pair<string, int>("digit", 0));
    maps.insert(pair<string, int>("space", 0));
    maps.insert(pair<string, int>("other", 0));
    for(int i = 0; str[i] != '\0'; i++)
    {
        if(isalpha(str[i])) maps["letter"]++;
        else if(isdigit(str[i])) maps["digit"]++;
        else if(isspace(str[i])) maps["space"]++;
        else maps["other"]++;
    }

    cout << "letter:" << maps["letter"] <<" digit:" << maps["digit"] << " space:" << maps["space"] << " other:" << maps["other"];
}

全部评论

相关推荐

mama3925:建议专业技能里测试移到最上面,加粗。然后适当加入些自动化测试工具。第二个项目,第三条亮点最后错别字。然后佬如果对自己很自信的话,可以项目放前面,然后项目里可以编造点测试经历,写在写在项目亮点的前两行。最后可加个自我评价,放个博客或者仓库链接
点赞 评论 收藏
分享
asdasdasdasdas:19岁,不容易啊可能升个本会好点,现在学历歧视太严重了
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务