Who is the highest in dormitory 7-4?

Source: Internet
Author: User

The school selects basketball players. Each dormitory can contain up to four people. The dormitory list is provided. Find the highest student in each dormitory. Define a student with height and weight such as weight.

Input Format:

First, enter an integer number N (1 <=n <= 1000000), indicating N students.
Enter n rows in the format of Dormitory number, name, height, and weight.
The dormitory number ranges from 0 to. The name is composed of letters, with a length less than 16, height, and weight as a positive integer.

Output Format:

Sort by Dormitory number from small to large, and output the highest height student information in each dormitory. Ensure that only one student in the dormitory is of the highest height.

Input example:
7000000 Tom 175 120000001 Jack 180 130000001 Hale 160 140000000 Marry 160 120000000 Jerry 165 110000003 ETAF 183 145000001 Mickey 170 115
Output example:
000000 Tom 175 120000001 Jack 180 130000003 ETAF 183 145

 

 

 

Code Implementation

# Include <iostream> # include <map> # include <string> using namespace STD; class student {public: string name; int h = 0; int W ;}; student s [1000000]; // placed in the super range of the main function int main () {int N, P = 0; CIN> N; bool isendl = false; Map <int, student> MP; int num; For (INT I = 0; I <n; I ++) {CIN> num; CIN> S [I]. name> S [I]. h> S [I]. w; If (MP [num]. h <s [I]. h) {MP [num] = s [I] ;}} for (Auto it = MP. begin (); it! = MP. end (); It ++) {If (isendl) {cout <Endl;} isendl = true; printf ("% 06d", It-> first ); cout <''<it-> second. name <''<it-> second. h <''<it-> second. W ;}}

Map container details

Map is the template, a map variable key and value. here you want to use a variable similar to map <int, int> m_map to represent the things in the backpack, m_map-> first can get the key value, m_map-> second can get the value; Map Automatically sorts the key value in ascending order, the key value cannot be modified, and the value can be modified.

11367285

 

 

 

I do not know that the array is not out-of-range.

Another solution

# Include <iostream> # include <string> # include <iomanip> using namespace STD; class student {public: int ID; string name; int h = 0; int W ;}; student s [1000000]; int main () {int N, P = 0; CIN> N; For (INT I = 0; I <1000000; I ++) // because the dormitory numbers may not be arranged in sequence, such as 000001 000003 000004 s [I]. id = I; Student Stu; bool isendl = false; For (INT I = 0; I <n; I ++) {CIN> Stu. id> Stu. name> Stu. h> Stu. w; If (Stu. h> S [STU. id]. h) {s [STU. id]. name = Stu. name; s [STU. id]. H = Stu. h; s [STU. id]. W = Stu. w; P ++ ;}}for (INT I = 0; I <1000000; I ++) {If (s [I]. H = 0) continue; If (isendl) {cout <Endl;} isendl = true; printf ("% 06d", s [I]. ID); cout <''<s [I]. name <''<s [I]. h <''<s [I]. W ;}}

 

Who is the highest in dormitory 7-4?

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.