SimeonTs

SUPyF2 Text-Pr.-Ex. - 09. Rage Quit

Oct 27th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.52 KB | None | 0 0
  1. """
  2. Text Processing - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1740#8
  4.  
  5. SUPyF2 Text-Pr.-Ex. - 09. Rage Quit (not included in final score)
  6.  
  7. Problem:
  8. Every gamer knows what rage-quitting means. It’s basically when you’re just not good enough and you blame everybody
  9. else for losing a game. You press the CAPS LOCK key on the keyboard and
  10. flood the chat with gibberish to show your frustration.
  11. Chochko is a gamer, and a bad one at that. He asks for your help; he wants to be the most annoying kid in his team,
  12. so when he rage-quits he wants something truly spectacular. He’ll give you a series of strings followed by non-negative
  13. numbers, e.g. "a3"; you need to print on the console each string repeated N times;
  14. convert the letters to uppercase beforehand. In the example, you need to write back "AAA".
  15. On the output, print first a statistic of the number of unique symbols used (the casing of letters is irrelevant,
  16. meaning that 'a' and 'A' are the same); the format shoud be "Unique symbols used {0}".
  17. Then, print the rage message itself.
  18. The strings and numbers will not be separated by anything.
  19. The input will always start with a string and for each string there will be a corresponding number.
  20. The entire input will be given on a single line; Chochko is too lazy to make your job easier.
  21. Input
  22. • The input data should be read from the console.
  23. • It consists of a single line holding a series of string-number sequences.
  24. • The input data will always be valid and in the format described. There is no need to check it explicitly.
  25. Output
  26. • The output should be printed on the console. It should consist of exactly two lines.
  27. • On the first line, print the number of unique symbols used in the message.
  28. • On the second line, print the resulting rage message itself.
  29. Constraints
  30. • The count of string-number pairs will be in the range [1 … 20 000].
  31. • Each string will contain any character except digits. The length of each string will be in the range [1 … 20].
  32. • The repeat count for each string will be an integer in the range [0 … 20].
  33. • Allowed working time for your program: 0.3 seconds. Allowed memory: 64 MB.
  34. Examples:
  35. Input:
  36. a3
  37. Output:
  38. Unique symbols used: 1
  39. AAA
  40. Comments:
  41. We have just one string-number pair. The symbol is 'a', convert it to uppercase and repeat 3 times: AAA.
  42. Only one symbol is used ('A').
  43.  
  44. Input:
  45. aSd2&5s@1
  46. Output:
  47. Unique symbols used: 5
  48. ASDASD&&&&&S@
  49. Comments:
  50. "aSd" is converted to "ASD" and repeated twice; "&" is repeated 5 times; "s@" is converted to "S@" and repeated once.
  51. 5 symbols are used: 'A', 'S', 'D', '&' and '@'.
  52. # TODO 50/100 Judge - TASK IS CORRECT time limit needs to be at least 0.205s to pass (at the moment is 0.100s)
  53. """
  54. rage = [item for item in input()]
  55. index = 0
  56. result = ""
  57. current_text = ""
  58. current_num = ""
  59.  
  60. while index != (len(rage) - 1):
  61.     try:
  62.         while not rage[index].isdigit():
  63.             current_text += rage[index].upper()
  64.             index += 1
  65.     except Exception:
  66.         result += current_text * int(current_num)
  67.         current_text = ""
  68.         current_num = ""
  69.         break
  70.     try:
  71.         while rage[index].isdigit():
  72.             current_num += rage[index]
  73.             index += 1
  74.     except Exception:
  75.         result += current_text * int(current_num)
  76.         current_text = ""
  77.         current_num = ""
  78.         break
  79.     result += current_text * int(current_num)
  80.     current_text = ""
  81.     current_num = ""
  82.  
  83. print(f"Unique symbols used: {len(set(result))}")
  84. print(result)
Add Comment
Please, Sign In to add comment