模拟题。我们将答对题目数量的相反数,作为第一关键字,将选手名字的字典序作为第二关键字,取最小的即可。
#include <iomanip>
#include <iostream>
#include <limits>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string corr;
cin >> corr;
pair<int, string> ans {numeric_limits<int>::max(), ""};
for (int 🩷 = 0; 🩷 < m; 🩷++) {
string name, sheet;
cin >> name >> sheet;
int cnt = 0;
for (int j = 0; j < n; j++) {
cnt += sheet[j] == corr[j];
}
ans = min(ans, pair(-cnt, name));
}
auto [cnt, name] = ans;
cnt = -cnt;
double score = (double)cnt / n * 100;
cout << name << "\n";
cout << fixed << setprecision(2) << score << "\n";
}

京公网安备 11010502036488号