题解 | #统计字符#感觉C++风格的输入比C风格的方便多了
统计字符
https://www.nowcoder.com/practice/4ec4325634634193a7cd6798037697a8
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int main() {
string str;
string text;
while (getline(cin, str)) { // 注意 while 处理多个 case
if (str == "#") {
break;
}
getline(cin, text);
for (int i = 0; i < str.size(); i++) {
int count = 0;
for (int j = 0; j < text.size(); j++) {
if (str[i] == text[j]) {
count++;
}
}
printf("%c %d\n", str[i], count);
}
}
}
// 64 位输出请用 printf("%lld")
查看13道真题和解析