#55276: cpp_answer


yp11451202@yphs.tp.edu.tw (705-38黃鈺潤)


#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n;
    // 使用 while (cin >> n) 以處理多組測資(雖然題目說只有一組,但這是好習慣)
    while (cin >> n) {
        string s;
        cin >> s;

        string compressed = "";
        int count = 1;

        for (int i = 0; i < n; ++i) {
            // 檢查下一個字元是否相同
            if (i + 1 < n && s[i] == s[i + 1]) {
                count++;
            } else {
                // 將數量與字元加入壓縮後的字串
                compressed += to_string(count) + s[i];
                count = 1; // 重置計數
            }
        }

        // 判斷壓縮後是否真的有比較短
        if (compressed.length() < s.length()) {
            cout << compressed << endl;
        } else {
            cout << s << endl;
        }
    }
    return 0;
}