📌  相关文章
📜  如何在 c 中查找字符串中不同字符的总数 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:51.241000             🧑  作者: Mango

代码示例1
#include 
#include 
using namespace std;

int main()
{
    string username;
    int count = 0;
    cin >> username;
    sort(username.begin(),username.end()); //for understanding purpose, i do it
    int slen = username.length();
    //cout << username << endl;
    for(int i = 0; i < slen; i++)
    {
        
            if(username[i] != username[i-1])
            {
                count++;
            }
        
    }
    
    cout << "Total number of distinct characters  :  " << count << endl;
    return 0;
}