题解 | #字符的个数#
字符的个数
https://www.nowcoder.com/practice/dc28f2bf113a4058be888a5875206238
#include <iostream> using namespace std; int main() { // 字符串 并接受用户的输入 string str; cin >> str; int countA, countB, countC; //定义并初始化三个计次变量 countA = 0; countB = 0; countC = 0; char* z = &str[0]; // 开始遍历字符串 for (int i = 0; i < str.length(); i++) { if ( *z == 'a') { countA++; } if (*z == 'b') { countB++; } if (*z == 'c') { countC++; } z++; } // 输出 cout << countA << " " << countB << " " << countC; }