Run ID:113275

提交时间: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; }