Editorial for Nén xâu


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Spoiler Alert


Hint 1

Duyệt qua xâu, và đếm số lượng kí tự bằng nhau liền nhau.

Xuất kết quả và chuyển sang kí tự tiếp theo

Reference AC code | O(n) time | O(1) auxiliary space | String, Online Solving

C++
for (char c = getchar(), p = c; c != EOF; p = c)
{
    int cnt = 0;
    while (p == c) cnt++, c = getchar();
    if (cnt > 1) cout << cnt;
    cout << p;
}


Comments

There are no comments at the moment.