When character are consecutive in a string , it is possible to shorten the character string by replacing the character with a certain rule. For example,

  • برمجة بي اتش بي

When character are consecutive in a string , it is possible to shorten the character string by replacing the character with a certain rule. For example, in the case of the character string YYYYY, if it is expressed as # 5 Y, it is compressed by one character.
Write a PHP program to restore the original string by entering the compressed string with this rule. However, the # character does not appear in the restored character string.
Note: The original sentences are uppercase letters, lowercase letters, numbers, symbols, less than 100 letters, and consecutive letters are not more than 9 letters.

Input: Multiple character strings are given. One string is given per line

الأجوبة

<?php
$str  = "@88 + 1 = 1@80";
    $index = 0;
    $result = array();
    while($index < strlen($str)) {
        $t = $str[$index++];
        if ($t == "@") {
            $len = $str[$index++];
            $char = $str[$index++];
            $run = "";
            for ($i = 0; $i < $len; $i++) {
                $run .= $char;
            }
            $result[] = $run;
        } else {
            $result[] = $t;
        }
    }
    echo implode("", $result);
?>

Sample Input:
@88 + 1 = 1@80

Sample Output:

88888888 + 1 = 100000000
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...