题解 | #字符个数统计#

字符个数统计

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

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

int main() {
    string str;
    int len;
    int count = 0;
    cin >> str;
    len = str.length();
    //cout << char(126)<<endl;
    for (int i = 0; i<=127;i++)
        {
            if (str.find(char(i))<=len-1 && str.find(char(i))>=0) 
            count++;
        }
    cout<< count;
    return 0;
}
// 64 位输出请用 printf("%lld")

利用string自带的find函数

用ASCII码为参照来做比较

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务