Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
113275 | 彭士宝 | 字母概率 | C++ | Accepted | 5 MS | 276 KB | 748 | 2025-03-15 16:20:42 |
#include <iostream> #include <string> #include <cctype> // 用于tolower函数 #include <iomanip> // 用于控制输出格式 using namespace std; int main() { string letter, word; while (cin >> letter >> word) { // 将输入的字母转换为小写 char target = tolower(letter[0]); // 统计目标字母在单词中出现的次数 int count = 0; for (char c : word) { if (tolower(c) == target) { count++; } } // 计算概率并输出,保留5位小数 double probability = static_cast<double>(count) / word.length(); cout << fixed << setprecision(5) << probability << endl; } return 0; }