Hdu1263 simple Simulation

Source: Internet
Author: User

Question: Output Based on the fruit sales table in a specific format

Format: sort by origin, and then sort by fruit name in the same origin.

Note: first, design multi-level sorting

Second, the same fruit in the same origin may appear multiple times, so you need to traverse the input fruit and find it once.

Third, here

# Include <iostream> # include <string> # include <algorithm> using namespace STD; int flag; // number of fruit types with different names in different regions struct node {string name, ID; int sum; bool operator <(const node & N) const {If (ID = n. ID) return name <n. name; else return id <n. id ;}} node [105]; void print (INT m) {for (INT I = 0; I <flag;) {string id = node [I]. ID; cout <id <Endl; cout <"| ----" <node [I]. name <'(' <node [I]. sum <')' <<Endl; I ++; while (ID = node [I]. ID & I <m) {cout <"| ----" <node [I]. name <'(' <node [I]. sum <')' <Endl; I ++ ;}} int main () {int n, m; CIN >>n; string name, ID; int sum; while (n --) {CIN> m; flag = 0; For (INT I = 0; I <m; I ++) {CIN> Name> ID> sum; Int J; For (j = 0; j <I; j ++) // search for the previous {If (name = node [J]. name & id = node [J]. ID) {node [J]. sum + = sum; break;} I F (I = J) // It is not found in the previous fruit, so it is a new fruit node [flag]. id = ID, node [flag]. name = Name, node [flag ++]. sum = sum;} Sort (node, node + flag); print (m); If (n! = 0) cout <Endl; // empty rows in the middle of the two cases} return 0 ;}


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.