ZeroJudge F277: Club Members' Information

Hail to the success of Beiyi Machinery Research Institute! In the academic year 109, the enrollment was a great success! With over 700 students in the entire school, 698 students chose Machinery Research Institute as their first choice. As the largest society in Beiyi, Machinery Research Institute naturally accepted all students. However, due to the low efficiency and quality of the school's administration, the list received was in a mess, causing a headache for the president. So, painstakingly, the data of 698 students (name, class, seat number, profile) were manually sorted according to class and seat number. Watching from the side, the programming instructor couldn't bear it and wanted to write a program to benefit the future leaders. However, she was also clueless, and after thinking for a long time, she couldn't come up with a solution. Please help write a program to sort the data of club members by class, and if the classes are the same, sort them by seat number.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
Each test case begins with a line containing N, representing the number of graduating students. This is followed by N lines of input, formatted as follows: Name Class SeatNumber Profile Where "Name" and "Profile" do not contain any spaces, and "Class" and "SeatNumber" are integers. (N <= 10^5)Please output the sorted list of member information. For each member, output two lines: The first line should be: Class SeatNumber Name (separated by spaces) The second line should be: Profile
3
陳希臻 15 12 我喜歡吸貓
鄭允臻 14 27 我討厭陳芭樂
魏家琦 8 37 我其實是白家琦
8 37 魏家琦
我其實是白家琦
14 27 鄭允臻
我討厭陳芭樂
15 12 陳希臻
我喜歡吸貓
ZeroJudge F277 範例測資

Thought Process

Store "Class" and "SeatNumber" in a Pair, and store them in an array/Vector. Then, store "Name" and "Profile" in a Pair. Declare a Map<pair, pair> data type, where the Key is a Pair of "Class" and "SeatNumber," and the Value is a Pair of "Name" and "Profile."

Sort the array/Vector containing Pair in ascending order. Then, sequentially output the "Class" and "SeatNumber" from the array/Vector. At the same time, use the Value corresponding to the Pair from the Map to output the Pair of "Name" and "Profile."

Sample Code-ZeroJudge F277: Club Members' Information

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

pair<int, int> rtn(int a, int b)
{
    pair<int, int>tmp;
    tmp.first = a;
    tmp.second = b;
    return tmp;
}

pair<string, string> pp (string a, string b)
{
    pair<string, string>tmp;
    tmp.first = a;
    tmp.second = b;
    return tmp;
}

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>>v;
    map<pair<int, int>, pair<string, string>>MAP;
    for (int i = 0; i<N; i++)
    {
        string name, word;
        int c, no;
        cin >> name >> c >> no >> word;
        pair<int, int>p = rtn(c, no);
        v.push_back(p);
        MAP[p] = pp(name, word);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i<N; i++)
    {
        cout << v[i].first << " " << v[i].second << " " << MAP[v[i]].first << "\n" << MAP[v[i]].second << "\n";
    }
}

//ZeroJudge F277
//Dr. SeanXD

Comments