题解 | #字符个数统计#

字符个数统计

https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50?tpId=37&tqId=21233&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=

#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    getline(cin,str);
    int len =str.length();
    int count =len;      //初始化统计字符数为字符串长度
    int num[500] ={0};      //用于标记已经被比较过的相同字符
    for(int i =0;i <len;i++){
        for(int j =len -1;j >i;j--){
            if(str[i] == str[j] && num[i] ==0){
                count--;
                num[j] =1;      //将已经比较过的相同字符排除出后续的比较序列
            }
        }
    }
    cout << count << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

小牛炒肉:好大的官威居然不是什么官
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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