题解 | 牛牛的考试

牛牛的考试

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

*/

全部评论

相关推荐

11-06 16:50
门头沟学院 Java
用微笑面对困难:word打字比赛二等奖的我,也要来凑合凑合
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务