题解 | 牛牛的考试

牛牛的考试

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

*/

全部评论

相关推荐

09-25 00:00
已编辑
电子科技大学 Java
球球与墩墩:这不是前端常考的对象扁平化吗,面试官像是前端出来的 const flattern = (obj) => { const res = {}; const dfs = (curr, path) => { if(typeof curr === 'object' && curr !== null) { const isArray = Array.isArray(curr); for(let key in curr) { const newPath = path ? isArray ? `${path}[${key}]` : `${path}.${key}` : key; dfs(curr[key], newPath); } } else { res[path] = curr } } dfs(obj); return res; }
查看3道真题和解析
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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