题解 | #字符个数统计#

字符个数统计

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")

全部评论

相关推荐

昨天 17:14
中北大学 Java
兄弟们是真是假
牛客46374834...:我在boss上投java岗从来没成功过
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 17:58
点赞 评论 收藏
分享
点赞 评论 收藏
分享
自学java狠狠赚一...:骗你点star的,港卵公司,记得把star收回去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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