Submission

Status:
[PPPPP][PPPPP]

Score: 100

User: Punnawith

Problemset: จุดแวะพัก

Language: cpp

Time: 0.015 second

Submitted On: 2025-03-23 10:36:31

#include<bits/stdc++.h>
using namespace std;

#define Student pair<int, string>

vector<Student> studentList;
int totalStudents, target;

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    cin >> totalStudents >> target;
    cin.ignore();
    
    for (int i = 0; i < totalStudents; i++) {
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
        string inputLine;
        getline(cin, inputLine);
        
        string name;
        string number;
        int cnt = 0;
        
        for (char ch : inputLine) {
            if (ch >= 'a' && ch <= 'z') {
                name.push_back(ch);
            } else if (ch == ' ') {
                number.clear();
            } else {
                number.push_back(ch);
                
                if (stoi(number) == target) {
                    studentList.push_back({cnt, name});
                    break;
                }
                cnt++;
            }
        }
    }
    
    if (studentList.empty()) {
        cout << -1;
        return 0;
    }
    
    sort(studentList.begin(), studentList.end());
    int studentCount = 0;
    for(auto student : studentList) {
        cout << student.second << ' ';
        studentCount++;
        if(studentCount == 3) return 0;
    }
    
    return 0;
}