Run ID:118434

提交时间:2025-05-01 22:26:27

#include <iostream> #include <string> using namespace std; int main() { string input; getline(cin, input); // 读取整行输入 // 将所有字符转换为大写 for (char& c : input) { if (islower(c)) { c = toupper(c); } } // 初始化变量 char current_char = input[0]; int count = 1; string result; // 遍历字符串 for (size_t i = 1; i < input.length(); ++i) { if (input[i] == current_char) { // 如果当前字符与前一个字符相同,计数加1 count++; } else { // 如果当前字符与前一个字符不同,输出当前字符及其计数 result += "(" + string(1, current_char) + "," + to_string(count) + ")"; // 更新当前字符和计数 current_char = input[i]; count = 1; } } // 输出最后一个字符及其计数 result += "(" + string(1, current_char) + "," + to_string(count) + ")"; // 输出最终结果 cout << result << endl; return 0; }