题解 | #字符个数统计#

字符个数统计

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

#include <iostream>
using namespace std;


//
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int check[127]={0};
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(!check[s[i]])
        {
            count++;
            check[s[i]]=1;
        }
    }
    cout<<count;
}
和上一题一样。 都是用一个数组来记录字符是不是已经有过。
全部评论

相关推荐

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