All submissions for this problem are available.
Kosmo is Mars’ biggest company, they generate over 50% of the entire planet's economy. They have a headquarters located in the capital city of Ares. Kosmo HQ is an amazingly large building, with over a thousand floors, with offices, stores, labs, and manufacturing. The entire network of Kosmo HQ is very interwoven, with every person being connected to several people through multiple ways.
Every person has exactly one direct supervisor and they may have any number of subordinates. Each person works on exactly one floor, and the higher the floor number, the higher the position. The salary of each employee is also connected to this network. If a person has employees, their salary is half of sum of their employees salary plus the difference between their most paid employee and least paid employee. Those that don't have employees make a base salary. For example, if a person has three employees having salaries of $60k, $70k and $80k respectively, he/she has a salary of ( (60+70+80)/2 + (80-60) ) = $125k. If a person has only 1 subordinate, they will receive 150% of their subordinate’s salary.
Kosmo is hiring a new software engineer to develop a system that allows for them to keep track of their employees and their relations. You've been hired to design this system. The system needs to be able to create a data structure that keeps track of all employees and their relations. Furthermore, the system must be able to keep track of their salaries and check to see if there's any discrepancies in pay. Lastly, the system must be able to locate whether an employee is in another employee's subordinate tree.
Your program will read input from stdin that will contained an unordered list of all the employees in the company. Each line will contain all the information for a single employee, where each employee has a first and last name:
(Employee Name) (Floor) (Salary) (Boss's Name)
Cirth Nade 5 23000 Dart Vade
There are some key exceptions. First, if there is a person who does not have a boss, that person is the CEO of the corporation. Second, some employees will have a hidden salary, your system must be able to deduce the approximation of that person's salary.
Example of a CEO entry: Tine Pal 1200 30000000000 -
Example of missing salary entry: Job Boe 3 - Vvaly Hay
This list will be followed by a ‘0’ character, signifying the end of the list. Thus, after reading in the input, your program needs to be able to execute commands as follows:
Input: Search (Employee Name)
Return: (Employee Name) (Number of Total Subordinates) (Boss) (What level of the tree they are on)
Input: Search (Employee Name #1), (Employee Name #2)
Return: (Employee Name #1) is (number of links) links away from (Employee Name #2)
Input: Subordinate (Employee Name #1), (Employee Name #2)
Return: (Employee Name #1) is in the subordinate tree of (Employee Name #2)
(Employee Name #1) is not in the subordinate tree of (Employee Name #2)
Input: Calculate Salary
Return: All salaries match accordingly
There is a discrepancy at (Employee Name)
Note that there will only be one person at most with a discrepancy.
The list of commands will be followed by a ‘0’ character signifying the end of all the commands. Nothing follows after the second ‘0’ character.
Aberdeen Aberdeen 3 60000 -
Bantering Bantha 2 50000 Aberdeen Aberdeen
Canth Catha 2 - Aberdeen Aberdeen
Clari Cla 1 10000 Bantering Bantha
Domink Lud 1 20000 Bantering Bantha
Frill Frog 1 30000 Bantering Bantha
Gresy Monro 1 20000 Canth Catha
Hop Ih 1 20000 Canth Catha
Search Hop Ih
Search Clari Cla, Canth Catha
Subordinate Gresy Monro, Bantering Bantha
Hop Ih 0 Canth Catha 3
Clari Cla is 3 links away from Canth Catha
Gresy Monro is not in the subordinate tree of Bantering Bantha
There is a discrepancy at Aberdeen Aberdeen
Note: There is NO newline character at the end of the output.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.