Advertisement
Guest User

Untitled

a guest
Mar 31st, 2023
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. line = input().upper()
  2.  
  3. final_string = ""
  4.  
  5. current_string_to_repeat = ""
  6.  
  7. unique_symbols = 0
  8.  
  9. # there are 2 stages of processing each string-number sequence
  10. # to keep the current stage in stageOfProcessing:
  11. # 1- collecting symbols for current_string.
  12. # 2- collecting digits for number
  13. stageOfProcessing = 1
  14.  
  15. current_number_to_repeat = ''       # number can contain multiple digits
  16.  
  17. for ch in line:
  18.     if ch.isdigit() and stageOfProcessing == 1:         # current char is digit, and it is the first one of the number
  19.         current_number_to_repeat += ch
  20.         stageOfProcessing = 2
  21.  
  22.     elif ch.isdigit() and stageOfProcessing == 2:       # current char is digit, but not the first one of the number
  23.         current_number_to_repeat += ch
  24.  
  25.     elif stageOfProcessing == 1:                        # current char is not a digit, so we collect symbols
  26.         current_string_to_repeat += ch
  27.  
  28.     elif stageOfProcessing == 2:                        # end of the current string-number sequence
  29.         final_string += current_string_to_repeat * int(current_number_to_repeat)
  30.         current_string_to_repeat = ch
  31.         current_number_to_repeat = ''
  32.         stageOfProcessing = 1
  33.  
  34. final_string += current_string_to_repeat * int(current_number_to_repeat)        # to add the last string-number sequence
  35. unique_symbols = len(set(final_string))                                         # take unique symbols count from result
  36. print(f"Unique symbols used: {unique_symbols} \n{final_string}")
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement