Submission
Status:
[PPPPP][PPPPP]
Score: 100
User: njoop
Problemset: จุดแวะพัก
Language: cpp
Time: 0.007 second
Submitted On: 2025-03-09 23:47:58
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, string>> ans;
int n, k, rest, cnt;
string s, name;
int transform(string num) {
int mul = 1, ans = 0;
reverse(num.begin(), num.end());
for(int i=0; i<num.size(); i++) {
ans += (num[i]-'0')*mul;
mul *= 10;
}
return ans;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
cin.ignore();
cin >> s;
while(n--) {
cnt = 0;
name = s;
while(cin >> s) {
bool nt=0;
cnt++;
for(char i: s) {
if(i < '0' || i > '9') nt=1;
}
if(nt) break;
rest = transform(s);
if(rest == k) {
ans.push_back({cnt, name});
}
}
}
sort(ans.begin(), ans.end());
if(ans.size() == 0) cout << -1;
else {
for(int i=0; i<min(3, int(ans.size())); i++) {
cout << ans[i].second << " ";
}
}
return 0;
}