Advertisement
jumboframe

Untitled

Jul 4th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. '''
  2. Shellbound
  3.  
  4. Vladi is a crab. Crabs are scared of almost anything, which is why they usually hide in their shells. Vladi is a rich
  5. crab though. He has acquired many outer shells, in different regions, in which he can hide – each with a different size.
  6. However, it is really annoying to look after all your shells when they are so spread out. That is why Vladi decided to
  7. merge all shells in each region, so that he has one big shell for every region. He needs your help to do that.
  8.  
  9. You will be given several input lines containing a string and an integer, separated by a space. The string will
  10. represent the region’s name, and the integer – the shell in the given region, size.
  11. You must store all shells in their corresponding regions.
  12. If the region already exists, add the new shell to it. Make sure you have NO duplicate shells (shells with same size).
  13. Vladi doesn’t like shells to have the same size.
  14.  
  15. When you receive the command “Aggregate”, you must stop reading input lines, and you must print every region, all of
  16. the shells in that region, and the size of the giant shell after you’ve merged them in the following format:
  17.  
  18. {regionName} -> {shell 1, shell 2…, shell n…} ({giantShell})
  19.  
  20. The giant shell size is calculated when you subtract the average of the shells from the sum of the shells.
  21. Or in other words: (sum of shells) – ((sum of shells) / (count of shells)).
  22.  
  23. Constraints
  24. All numeric data will be represented with integer variables in range [0…1.000.000.000].
  25.  
  26. Examples
  27.  
  28. Input                       Output
  29.  
  30. Sofia 50                    Sofia -> 50, 20, 30 (67)
  31. Sofia 20                    Varna - 10, 20 (15)
  32. Sofia 30
  33. Varna 10
  34. Varna 20
  35. Aggregate
  36.  
  37.  
  38.  
  39.  
  40.  
  41. Sofia 2                     Sofia -> 2, 1 (2)
  42. Sofia 1                     Plovdiv -> 100, 50 (75)
  43. Plovdiv 100
  44. Plovdiv 50
  45. Aggregate
  46. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement