+ 2
The weird number 48 . Text Decompressor | code coach
So I solved this code coach Text Decompressor and I don't know that's up with that 48 on the jagged for loop in line 12 using System; namespace SoloLearn { class Program { static void Main(string[] args) { char[] text = Console.ReadLine().ToCharArray(); for(int i = 0;i <= text.Length; i += 2) { for (int a = 0;a < (int)text[i + 1] - 48;a++) { Console.Write(text[i]); } } } } }
5 Réponses
+ 1
48 is a number of '0' character in asci table. When you subtract 48 from a code of a character (from 0 to 9) it is like cast from char to int. More explicit way to do it -
Convert.ToInt32(text[i+1]);
+ 1
You need to decompress text. The compressed version has a number next to each symbol/letter, representing the amount of time that symbol should appear.
For example, a2b3 is the compressed version of aabbb
Task:
Write a program that takes the compressed text as input and outputs the decompressed version.
Input Format:
A single string with letters/symbols, each followed by a number.
Output Format:
A string, representing the decompressed text.
Sample Input:
k2&4b1
Sample Output:
kk&&&&b
+ 1
compressed_string = input()
decompressed_string = " "
for i in compressed_string:
if not i.isdigit():
decompressed_string += i * int(compressed_string[(compressed_string.index(i)+1)])
print(decompressed_string)
0
Task condition is not available for those who do not have pro-status. It will be easier if you write the condition here.
0
di dog can code ńįçę