Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
113269 彭士宝 字母概率 C++ Compile Error 0 MS 0 KB 991 2025-03-15 16:14:47

Tests(0/0):


Code:

#include <iostream> #include <string> #include <cctype> // 用于tolower函数 #include <iomanip> // 用于设置输出格式 using namespace std; int main() { string input; while (getline(cin, input)) { if (input.empty()) break; // 如果输入为空,结束程序 // 分割输入的字母和单词 char letter = tolower(input[0]); // 将字母转换为小写 string word = input.substr(2); // 提取单词部分 transform(word.begin(), word.end(), word.begin(), ::tolower); // 将单词转换为小写 // 统计字母出现的次数 int count = 0; for (char c : word) { if (c == letter) { count++; } } // 计算概率 double probability = static_cast<double>(count) / word.length(); // 输出结果,保留5位小数 cout << fixed << setprecision(5) << probability << endl; } return 0; }


Run Info:

Main.cc: In function 'int main()':
Main.cc:16:68: error: 'transform' was not declared in this scope
         transform(word.begin(), word.end(), word.begin(), ::tolower); // 将单词转换为小写
                                                                    ^