TopCoder problem "ChangeReport" used in College Tour Sichuan (Division I Level Two)



Problem Statement

    

As a sales manager, you want to see how each of your staff members performed this year as compared to last year. For each staff member i, you are given their name (in the i-th element of names), their total sales for last year (in the i-th element of lastYearSales), and their total sales from the current year (in the i-th element of thisYearSales). From this data, produce a report that has one element for each person formatted as follows: the difference in sales, a space, and then that staff member's name. Here is a sample report output:

5 SAM
4 ALICE
4 BOB
-2 SUE
-18 ADAM
0 DAVE
0 FRED
0 XANDER

According to this data, SAM sold 5 more units this year than last year, and ADAM sold 18 less. The other thing to notice is how the report is sorted. At the top of the report is data for all staff whose performance has changed. These are sorted based on that staff member's change in sales, from largest gain down to largest drop. After this, list all the staff who had no change in sales. In the case of a tie in sales figures, sort the tied elements alphabetically by name. All names will be given uppercase only, with no spaces, and no name will occur more than once. Your return will have the same number of elements as there are staff in the input; return each line of the report as one element with no line breaks or extra spaces.

 

Return the sales change report for the given input, with formatting and sorting as specified.

 

Definition

    
Class:ChangeReport
Method:produceReport
Parameters:String[], int[], int[]
Returns:String[]
Method signature:String[] produceReport(String[] names, int[] lastYearSales, int[] thisYearSales)
(be sure your method is public)
    
 

Constraints

-names will contain between 1 and 50 elements, inclusive.
-names, lastYearSales, and thisYearSales will each contain the same number of elements.
-Each element of lastYearSales will be between 0 and 1000, inclusive.
-Each element of thisYearSales will be between 0 and 1000, inclusive.
-Each element of names will contain between 1 and 10 characters, inclusive.
-Each element of names will contain only uppercase letters ('A'-'Z').
-Each element of names will be distinct.
 

Examples

0)
    
{"PAT"}
{100}
{110}
Returns: {"10 PAT" }
PAT's sales figures went up by 10.
1)
    
{"ANNE","ZACHARY","ZAC","ZEKE","ANDREW"}
{0,0,0,0,0}
{0,0,0,0,0}
Returns: {"0 ANDREW", "0 ANNE", "0 ZAC", "0 ZACHARY", "0 ZEKE" }
2)
    
{"DAVE","JULIE","PETER","WENDY","DWIGHT"}
{100,200,150,50,9}
{120,240,140,10,9}
Returns: {"40 JULIE", "20 DAVE", "-10 PETER", "-40 WENDY", "0 DWIGHT" }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7474

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10949&pm=7474

Writer:

jmzero

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Sorting