Run-length encoding · ترميز المسارات
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.
تجول في السلسلة متتبعاً الحرف الحالي ومدى تطاول تتابعه. عندما يختلف الحرف التالي، اكتب التتابع (الحرف + العدد) وابدأ تتابعاً جديداً. لا تنسَ كتابة التتابع الأخير بعد انتهاء الحلقة.
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. · اضغط تشغيل لرؤية المخرجات هنا.