Hdu & amp; #65279; & amp; #65279; & amp; #65279; & amp

Source: Internet
Author: User
Tags sorted by name

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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.