Run ID:107360
提交时间:2025-01-17 15:31:46
#include <iostream> using namespace std; string compress(string str) { string result = ""; char currentChar = toupper(str[0]); int count = 1; for (int i = 1; i < str.length(); ++i) { if (toupper(str[i]) == currentChar) { count++; } else { result += "(" + currentChar + "," + to_string(count) + ")"; currentChar = toupper(str[i]); count = 1; } } result += "(" + currentChar + "," + to_string(count) + ")"; return result; } int main() { string input; cin >> input; cout << compress(input) << endl; return 0; }