Python Fundamentals -> Text Processing -> Rage Quit
Здравейте,
Text Processing -> Rage Quit: https://softuni.bg/trainings/resources/officedocument/74658/text-processing-exercise-programming-fundamentals-with-python-september-2022/3840
Опитвам се да реша задачата без regex, но ми дава само 28/100 в judge. Ако може малко помощ, защото не мога да намеря грешката си:
line = input().upper()
final_string = ""
current_string_to_repeat = ""
#count of unique symbols
unique_symbols = 0
for ch in line:
if ch.isdigit():
final_string += current_string_to_repeat * int(ch)
current_string_to_repeat = ""
else: #when ch is a letter or symbol eg @ # etc
current_string_to_repeat += ch
if ch not in final_string:
unique_symbols += 1
print(f"Unique symbols used: {unique_symbols} \n{final_string}")
Мерси много за коментара ти. Да, верно не проверявах дали числото може да е по-голямо от 9 (например а10 => АААААААААА). Добавих тази проверка и всичко тръгна!
line = input().upper() #the output text final_string = "" #creating temporary string that will be duplicated several time A3 => AAA current_string_to_repeat = "" #creating a string for the digit after the symbols that should be repeated A10 => AAAAAAAAAA current_digit_string = "" # count of unique symbols unique_symbols = 0 for i in range(len(line)): ch = line[i] if ch.isdigit(): #when ch is a digit #adding symbol to the digit string e.g. 1 + 3 + 2 => 132 current_digit_string += ch #checking if it's not the last symbol of our main string to avoid out of range if i == len(line) - 1: final_string += current_string_to_repeat * int(current_digit_string) #checking if the next symbol is a digit and adding continue so we can keep adding digits 1 + 3 + 2 => 132 elif line[i + 1].isdigit(): continue #adding symbols to the output string by multiplying it with the digit else: final_string += current_string_to_repeat * int(current_digit_string) #resetting current_string_to_repeat = "" current_digit_string = "" else: # when ch is a letter or symbol eg @ # etc current_string_to_repeat += ch if ch not in final_string: unique_symbols += 1 print(f"Unique symbols used: {unique_symbols} \n{final_string}")