codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

75B.md (2775B)


      1 Source: https://codeforces.com/problemset/problem/75/B
      2 
      3 B. Facetook Priority Wall
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).
     22 
     23 This priority factor will be affected by three types of actions:
     24 
     25 * 1. "*X* posted on *Y*'s wall" (15 points),
     26 * 2. "*X* commented on *Y*'s post" (10 points),
     27 * 3. "*X* likes *Y*'s post" (5 points).
     28 
     29 *X* and *Y* will be two distinct names. And each action will increase the priority factor between *X* and *Y* (and vice versa) by the above value of points (the priority factor between *X* and *Y* is the same as the priority factor between *Y* and *X*).
     30 
     31 You will be given *n* actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you.
     32 
     33 Input
     34 
     35 The first line contains your name. The second line contains an integer *n*, which is the number of actions (1 ≤ *n* ≤ 100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters.
     36 
     37 Output
     38 
     39 Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order.
     40 
     41 Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor.
     42 
     43 The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line *a* is lexicographically smaller than the line *b*, if either *a* is the prefix of *b*, or if exists such an *i* (1 ≤ *i* ≤ *min*(|*a*|, |*b*|)), that *a**i* < *b**i*, and for any *j* (1 ≤ *j* < *i*) *a**j* = *b**j*, where |*a*| and |*b*| stand for the lengths of strings *a* and *b* correspondently.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 ahmed  
     51 3  
     52 ahmed posted on fatma's wall  
     53 fatma commented on ahmed's post  
     54 mona likes ahmed's post
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 fatma  
     61 mona
     62 ```
     63 
     64 Input
     65 
     66 ```
     67 aba  
     68 1  
     69 likes likes posted's post
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 likes  
     76 posted
     77 ```