Fruit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 1553 Accepted Submission (s): 616
Problem Description
Summer is coming ~~ So happy, huh, a lot of fruit ~~
Joe runs a small fruit store. he believes that the way to survive is to manage the fruits that are most popular with customers. now he wants a list of fruit sales, so that Joe can easily grasp the sales of all fruits.
Input
The first positive integer N (0 <N <= 10) indicates that N groups of test data exist.
The first line of each group of test data is an integer M (0 <M <= 100), indicating that the job has M successful transactions. there are M rows of data, each row indicates a transaction, composed of fruit names (lowercase letters, length not more than 80), fruit origin (consisting of lowercase letters, length not more than 80) and the number of fruits in the transaction (positive integer, up to 100.
Output
For each set of test data, please output a detailed table of fruit sales information in the correct layout format (analyze sample output. this list includes the origin, name, and quantity of all fruits. fruits are sorted alphabetically by origin. fruits of the same origin are sorted by name, and names are sorted alphabetically.
There is an empty row between the two groups of test data. There is no blank row after the last group of test data.
Sample Input
1
5
Apple shandong 3
Pineapple guangdong 1
Sugarcane guangdong 1
Pineapple guangdong 3
Pineapple guangdong 1
Sample Output
Guangdong
| ---- Pineapple (5)
| ---- Sugarcane (1)
Shandong
| ---- Apple (3)
Map can also be used for sorting in this question.
[Cpp]
# Include <stdio. h>
# Include <string>
# Include <map>
# Include <iostream>
Using namespace std;
Int main ()
{
Int n, I, j, cas, m;
String name, space;
Scanf ("% d", & cas );
Map <string, map <string, int> mp;
While (cas --)
{
Mp. clear ();
Scanf ("% d", & n );
While (n --)
{
Cin> name> space> m;
Mp [space] [name] + = m;
}
Map <string, map <string, int >:: iterator it1;
For (it1 = mp. begin (); it1! = Mp. end (); it1 ++)
{
Cout <it1-> first <endl;
Map <string, int >:: iterator it2;
For (it2 = it1-> second. begin (); it2! = It1-> second. end (); it2 ++)
Cout <"" <"| ----" <it2-> first <"<it2-> second <") "<endl;
}
If (cas! = 0) cout <endl;
}
Return 0;
}