题解 | #字符个数统计#

字符个数统计

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

#include <iostream>
#include<algorithm>

using namespace std;

int main() {
    string str1;
    cin >> str1;
    int n = str1.length()-1;
    sort(str1.begin(), str1.end()); //将字符串排序,如果后一个跟前一个不相同就加一
    int count=1;
    for(int i=1; i<=n; i++){
        if(str1[i]!=str1[i-1]){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}
全部评论

相关推荐

12-24 14:26
东北大学 Java
一只乌鸦:重邮+东北,好经典的学校
最后再改一次简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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