Skip to content · ⁨דלג לתוכן⁩

Run-length encoding · ⁨אנכוד רצפים⁩

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.

עברית

ריצות-לונג'ית אנקודינג

דחסו מחרוזת על ידי החלפת כל רצף של אותות זהים באות עצמה ולאחריה כמה פעמים היא חוזרת: aaabbc → a3b2c1. תמיד כתבו את הספירה, גם כשהיא 1.

עברו על המחרוזת תוך מעקב אחרי האות הנוכחית ואורך הרצף שלה. כאשר האות הבא שונה, כתבו את הרצף (אות + ספירה) והתחילו רצף חדש. אל תשכחו לכתוב את הרצף האחרון לאחר שהלולאה נגמרת.

Log in or create account · ⁨היכנס או צור חשבון⁩

IGCSE, A-Level & AP