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,
- برمجة بي اتش بي
- 2021-09-08
- mhanasmh00489829403
الأجوبة
<?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
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال