Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
158654 章泽原 字母概率 C++ Accepted 5 MS 272 KB 585 2026-08-22 16:21:50

Tests(1/1):


Code:

#include <iostream> #include <string> #include <iomanip> #include <cctype> using namespace std; int main() { char ch; string word; // 多组输入,直到读完 while (cin >> ch >> word) { char target = tolower(ch); int cnt = 0; int len = word.size(); for (char c : word) { if (tolower(c) == target) cnt++; } double prob = 1.0 * cnt / len; // 保留5位小数输出 cout << fixed << setprecision(5) << prob << endl; } return 0; }