题解 | 扑克牌大小

扑克牌大小

https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb

#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
void prt(vector<vector<string>>& players) {
    for (auto p : players) {
        for (auto poke : p) {
            cout << poke;
        }
        cout << endl;
    }
    return;
}

void prt_pokes(vector<string>& pokes) {
    for (auto& p : pokes) {
        cout << p << " ";
    }
    cout << endl;
    return;
}

int pokeVal(string& s) {
    if (s.size() == 1) {
        char c = s[0];
        if (c >= '3' && c <= '9') {
            return c - '0';
        }
        if (c == 'J')
            return 11;
        if (c == 'Q')
            return 12;
        if (c == 'K')
            return 13;
        if (c == 'A')
            return 14;
        if (c == '2')
            return 15;
    }
    if (s.size() == 2)
        return 10;
    if (s[0] == 'j')
        return 16;
    return 17;
}

int main() {
    string s, spokes;
    vector<vector<int>> player_vals;
    vector<vector<string>> player_pokes;
    getline(cin, s);
    istringstream iss(s);
    while (getline(iss, spokes, '-')) {
        istringstream iss2(spokes);
        string poke;
        int poke_val;
        vector<int> player;
        vector<string> s_pokes;
        while (getline(iss2, poke, ' ')) {
            poke_val = pokeVal(poke);
            player.emplace_back(poke_val);
            s_pokes.emplace_back(poke);
        }
        player_vals.emplace_back(player);
        player_pokes.emplace_back(s_pokes);
    }
    //prt(players);
    int p1_pks = player_vals[0].size(), p2_pks = player_vals[1].size();
    if (p1_pks == p2_pks) {
        int pn = player_vals[0][0] > player_vals[1][0] ? 0 : 1;
        prt_pokes(player_pokes[pn]);
    } else {
        if (p1_pks == 2 || p2_pks == 2) {
            int pn = p1_pks == 2 ? 0 : 1;
            int pother = 1 - pn;
            if (player_vals[pn][0] == 16) {
                prt_pokes(player_pokes[pn]);
            } else {
                if (player_vals[pother].size() == 4) {
                    prt_pokes(player_pokes[pother]);
                } else {
                    cout << "ERROR";
                }
            }
        } else {
            if (p1_pks == 4 || p2_pks == 4) {
                int pn = p1_pks == 4 ? 0 : 1;
                prt_pokes(player_pokes[pn]);
            }else{
                cout << "ERROR";
            }
        }

    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

04-25 10:45
东南大学 Java
点赞 评论 收藏
分享
头像
04-17 09:29
已编辑
湖南农业大学 后端
睡姿决定发型丫:本硕末9也是0offer,简历挂了挺多,只有淘天 美团 中兴给了面试机会,淘天二面挂,美团一面kpi面,中兴一面感觉也大概率kpi(虽然国企,但一面0技术纯聊天有点离谱吧)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务