Submission
Status:
[PPPPP][PPPPP]
Score: 100
User: yumiKuri
Problemset: จุดแวะพัก
Language: cpp
Time: 0.003 second
Submitted On: 2025-03-23 15:04:20
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0), cin.tie(0);
int n,m;
cin >> n >> m;
vector<pair<int, string>> ans;
cin.ignore();
int count, temp;
for(int i = 0; i < n; i++){
string s;
getline(cin, s);
string name = "";
count = 0;
temp = 0;
for(int i = 0; i < s.length(); i++){
if(s[i] >= 'a' and s[i] <= 'z'){
name+= s[i];
}
else if(s[i] >= '0' and s[i] <= '9'){
if(s[i-1] >= '0' and s[i-1] <= '9') temp = temp*10 + (s[i] - '0');
else{
temp = s[i] - '0';
count++;
}
if(i+1 == s.length()){
if(temp == m){
ans.push_back({count, name});
break;
}
}
}
else{
if(temp == m){
ans.push_back({count, name});
break;
}
}
}
}
sort(ans.begin(), ans.end());
if(ans.size() == 0) cout << -1;
else{
for(int i = 0; i < 3; i++){
cout << ans[i].second << ' ';
}
}
}