Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- line = input().upper()
- final_string = ""
- current_string_to_repeat = ""
- unique_symbols = 0
- # there are 2 stages of processing each string-number sequence
- # to keep the current stage in stageOfProcessing:
- # 1- collecting symbols for current_string.
- # 2- collecting digits for number
- stageOfProcessing = 1
- current_number_to_repeat = '' # number can contain multiple digits
- for ch in line:
- if ch.isdigit() and stageOfProcessing == 1: # current char is digit, and it is the first one of the number
- current_number_to_repeat += ch
- stageOfProcessing = 2
- elif ch.isdigit() and stageOfProcessing == 2: # current char is digit, but not the first one of the number
- current_number_to_repeat += ch
- elif stageOfProcessing == 1: # current char is not a digit, so we collect symbols
- current_string_to_repeat += ch
- elif stageOfProcessing == 2: # end of the current string-number sequence
- final_string += current_string_to_repeat * int(current_number_to_repeat)
- current_string_to_repeat = ch
- current_number_to_repeat = ''
- stageOfProcessing = 1
- final_string += current_string_to_repeat * int(current_number_to_repeat) # to add the last string-number sequence
- unique_symbols = len(set(final_string)) # take unique symbols count from result
- print(f"Unique symbols used: {unique_symbols} \n{final_string}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement