Question Name:Monk’s School.

using namespace std;
typedef long long ll;
int main()
    ll n,m;
    string s[n];
    map<string ,ll> pam;
    //map<ll,string> pam2;
    for(ll i=0;i<n;i++)
    vector<pair<ll,string> > p[n];
    string S;
    for(ll i=0;i<m;i++)
        pair<ll,string> v;
        ll idx=pam[S];
    for(auto q=pam.begin();q!=pam.end();++q)
        ll i=(*q).second;
        for(ll j=0;j<p[i].size();j++)
            cout<<p[i][j].second<<" "<<p[i][j].first<<"\n";

Problem Description

Today is the 25th anniversary of Berland International School in Berland. On this auspicious Occasion, our friend Monk has been given the responsibility of preparing the Inventory for his school.
There are exactly N teachers and M students in the school. Each of these teachers teaches arbitary number of students. However, each student is taught by exactly one teacher.

Monk has been given the task of finding out for each teacher the Students he/she teaches. For each student Monk has been given the Student’s Name and Age. However , Monk is too busy , So he has assigned this task to us.

We need to print the name of the Teacher and the Name and age of the students that he/she teaches. However, there is a catch here. We need to print the list of students of each Teacher in Lexicographical order of their names . That is list of the teacher with lexicographically smaller name will appear before other teachers with lexicographically greater names.

In Addition , The students appearing in a particular teachers list should appear in Increasing order of their Age.

Input Format :

The first line contains two integers N and M denoting the number of Teachers and number of Students respectively. Each of the next N lines contain a single string denoting a Teachers name.It is guaranteed that each teachers name shall be unique.
The next M lines contain 2 Strings and an Integer, denoting the Teachers name, a Student’s name being taught by that Teacher and that Student’s Age. It is guaranteed that each Student’s name shall be unique and shall appear only once in the Input.

Output Format:

Print N+M lines . Print the teachers name first and then the name and age of each student taught by this teacher. The list of each teacher should appear in order of their lexicographical rank in comparison to all other teachers.

For example the list of the teacher with lexicographically smallest name should appear first, then the list of the teacher with the 2nd smallest lexicographical name and so on. The students in a particular teachers list should appear in the output in Increasing order of their Age.

1<=Age of Each Student<=106
1<=Length of each Student and Teachers Name <=35

The Name of Each Teacher and Student will consist of Lowercase English Alphabets only.

It is guaranteed that no two students with the same age shall appear in the same Teacher’s List.

Hint : You Need to Use Comparable Interface Here.

  • Test Case 1

    Input (stdin)

    3 4
    vasya errichto 21
    kolya petr 22
    petya egor 19
    vasya tourist 19

    Expected Output

    petr 22
    egor 19
    tourist 19
    errichto 21
  • Test Case 2

    Input (stdin)

    3 3
    cat e 2
    god ee 5
    dog eee 9

    Expected Output

    e 2
    eee 9
    ee 5

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro