题解 | #字符个数统计#

字符个数统计

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

//使用hash表可以解决重复元素问题,hash实现可以使用数组,动态数组以及map映射
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
    string s;
    map<char, int> hash;
    int count=0;
    while (cin >> s) { // 注意 while 处理多个 case
        
        for(int i=0;i<s.length();i++){

            if (hash[s[i]]==0){
                count++;
                hash[s[i]]=1;
            }

        }


        cout<<count<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

zygg:拼多多挂是不是过一两天就挂的呀
点赞 评论 收藏
分享
04-14 20:10
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务