+ 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]); } } } } }

3rd Mar 2020, 5:42 PM
Flayer
Flayer - avatar
5 Respostas
+ 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]);
3rd Mar 2020, 10:12 PM
Влад Антеев
Влад Антеев - avatar
+ 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
3rd Mar 2020, 9:57 PM
Flayer
Flayer - avatar
+ 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)
18th Nov 2021, 5:10 PM
Mas'ud Saleh
Mas'ud Saleh - avatar
0
Task condition is not available for those who do not have pro-status. It will be easier if you write the condition here.
3rd Mar 2020, 9:54 PM
Влад Антеев
Влад Антеев - avatar
0
di dog can code ńįçę
4th Mar 2020, 8:40 AM
Ezequiel