Skip to content · ⁨Pular para o conteúdo⁩

Run-length encoding · ⁨Codificação por comprimento de corrida⁩

English

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.

Português

Codificação por comprimento de corrida

Comprima uma string substituindo cada sequência do mesmo caractere por esse caractere seguido de quantas vezes ele se repete: aaabbc → a3b2c1. Sempre escreva o número, mesmo quando for 1.

Percorra a string acompanhando o caractere atual e quanto tempo dura sua sequência. Quando o próximo caractere diferir, escreva a sequência (caractere + número) e inicie uma nova sequência. Não esqueça de escrever a última sequência após o loop terminar.

Log in or create account · ⁨Entrar ou criar conta⁩

IGCSE, A-Level & AP