题解 | #扑克牌大小#

扑克牌大小

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

#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int get_level(vector<int>& v) {
    if (v.size() == 1) {
        return 1;
    }
    if (v.size() == 2) {
        return 2;
    }
    if (v.size() == 3) {
        return 3;
    }
    if (v.size() == 5) {
        return 4;
    }
    if (v.size() == 4) {
        return 5;
    }
    return 10;
}
void get_v(string& s, vector<int>& resv) {
    stringstream ss(s);
    string tem;
    while (ss >> tem) {
        int tem_num;
        if(tem.size()==5){
            if(tem[0]=='j'){
                tem_num = 50;
                resv.push_back(tem_num);
                continue;
            }if(tem[0]=='J'){
                tem_num = 100;
                resv.push_back(tem_num);
                continue;
            }

        }
        if (tem.size() == 2) {
            tem_num = 10;
            resv.push_back(tem_num);
            continue;
        } else if (tem.size() == 1) {
            if (tem[0] >= '0' && tem[0] <= '9') {
                resv.push_back(tem[0] - '0');
                continue;
            } else {
                if (tem[0] == 'J') {
                    resv.push_back(11);
                    continue;
                }
                if (tem[0] == 'Q') {
                    resv.push_back(12);
                    continue;
                }
                if (tem[0] == 'K') {
                    resv.push_back(13);
                    continue;
                }
                if (tem[0] == 'A') {
                    resv.push_back(14);
                    continue;
                }
            }
        }
    }
}
int main() {
    string l;
    string r;
    vector<int> lv;
    vector<int> rv;
    getline(cin, l, '-');
    getline(cin, r);
    //有对王
    if (l[0] == 'j'&&l.size()==11) {
        cout << l;
        return 0;
    }
    if (r[0] == 'j'&&r.size()==11) {
        cout << r;
        return 0;
    }
    //放入vector
    get_v(l, lv);
    get_v(r, rv);
    int lval = 0;
    int rval = 0;
    //获得等级
    lval = get_level(lv);
    rval = get_level(rv);
    //测试
    //cout<<"左侧为:"<<l<<" 等级为:"<<lval<<endl<<"右侧为:"<<r<<" 等级为:"<<rval<<endl;
    
    //等级相同才能比
    if ( lval == rval) {
        if (lv[0] > rv[0]) {
            cout << l;
            return 0;
        } else {
            cout << r;
            return 0;
        }
    } else {
        if (lval != 5 && rval != 5) {
            //等级不同时且无炸弹
            cout << "ERROR";
            return 0;
        } else {
            //等级不同有炸弹
            if(lval==5){
                cout<<l;return 0;
            }
            if(rval==5){
                cout<<r;return 0;
            }
        }
    }

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

又臭又长

全部评论

相关推荐

贺兰星辰:不要漏个人信息,除了简历模板不太好以外你这个个人简介是不是太夸大了...
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务