题解 | #字符的个数#
字符的个数
https://www.nowcoder.com/practice/dc28f2bf113a4058be888a5875206238
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; // 输出'a','b','c'出现次数 int na = 0, nb =0, nc = 0; for (int i = 0; i < s.length(); i++){ //s.size()也可以 if (s[i] == 'a') na++; if (s[i] == 'b') nb++; if (s[i] == 'c') nc++; } cout << na << " " << nb << " " << nc; return 0; }