Run-length encoding · 런-length 인코딩
Run-length encoding
Compress a string by replacing each run of the same character with that character followed by how many times it repeats: aaabbc → a3b2c1. Always write the count, even when it is 1.
Walk the string tracking the current character and how long its run is. When the next character differs, write out the run (character + count) and start a fresh run. Don't forget to write the last run after the loop ends.
루스 인코딩(RLE)
동일한 문자가 연속해서 나오는 **연속 부분(run)**을 해당 문자와 반복 횟수로 교체하여 압축합니다: aaabbc → a3b2c1. 횟수가 1일 때도 반드시 적으십시오.
현재 문자와 해당 연속 부분의 길이를 추적하며 문장을边走. 다음 문자가 다르면 연속 부분을 출력(문자 + 횟수)하고 새로운 연속 부분을 시작합니다. 루프가 끝난 후 마지막 연속 부분도 잊지 말고 출력하십시오.
Write run_length_encode(s) that compresses runs of the same character into the character followed by its run length, e.g. aaabbc becomes a3b2c1. Always include the count, even when it is 1. · 연속된 동일한 문자의 묶음을 해당 문자와 묶음 길이로 압축하는 run_length_encode(s)을 작성하세요. 예를 들어 aaabbc은 a3b2c1로 변합니다. 길이가 1일 때도 반드시 카운트를 포함해야 합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.