Submission
Status:
[PP-SS][PPPPP]
Score: 50
User: Punnawith
Problemset: จุดแวะพัก
Language: cpp
Time: 0.027 second
Submitted On: 2025-03-23 10:29:15
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define Student pair<int, string>
vector<Student> studentList;
int totalStudents, targetScore;
int main() {
cin >> totalStudents >> targetScore;
for (int i = 0; i < totalStudents; i++) {
string inputLine;
getline(cin, inputLine);
string name;
string number;
int index = 0;
for (char ch : inputLine) {
if (isalpha(ch)) {
name.push_back(ch);
} else if (ch == ' ') {
number.clear();
} else {
number.push_back(ch);
if (stoi(number) == targetScore) {
studentList.push_back({index, name});
break;
}
index++;
}
}
}
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;
}