题解 | 牛牛的考试
牛牛的考试
https://www.nowcoder.com/practice/1a7a7c8d721547a29107cf02330ffe72
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;
int main() {
int T;
cin >> T;
vector<string> strs;
string str;
array <int, 4> arr;
for (int i = 1; i <= T; i++) {
for (int j = 0; j < 4; j++) {
cin >> str;
strs.push_back(str);
arr[j] = strs[j].size();
}
sort(arr.begin(), arr.end());
if ((arr[0] < arr[1] && arr[1] < arr[2] && arr[2] < arr[3]) ||
(arr[0] < arr[1] && arr[1] == arr[2] && arr[2] < arr[3]) || (arr[0] == arr[1] &&
arr[1] == arr[2] && arr[2] == arr[3])) {
cout << strs[2][0] << endl;
} else if ((arr[0] == arr[1] && arr[1] < arr[2] && arr[2] < arr[3]) ||
(arr[0] == arr[1] && arr[1] == arr[2] && arr[2] < arr[3])) {
for (auto& str1 : strs) {
if (str1.size() == arr[3]) {
cout << str1[0] << endl;
}
}
} else {
for (auto& str2 : strs) {
if (str2.size() == arr[0]) {
cout << str2[0] << endl;
}
}
}
arr = {0, 0, 0, 0};
strs.clear();
}
return 0;
}
/*
3847
3478
4行 接收4s vector<
长度 sieze 存在 abcd
排序
1235 c
1123 长
1223 c
1255 短
1114 长
4441 短
1111 c
*/

查看3道真题和解析