首页 > 试题广场 >

扑克牌大小

[编程题]扑克牌大小
  • 热度指数:108802 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解

扑克牌游戏大家应该都比较熟悉了,一副牌由54张组成,含3~A、2各4张,小王1张,大王1张。牌面从小到大用如下字符和字符串表示(其中,小写joker表示小王,大写JOKER表示大王):
3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER
输入两手牌,两手牌之间用"-"连接,每手牌的每张牌以空格分隔,"-"两边没有空格,如:4 4 4 4-joker JOKER。
请比较两手牌大小,输出较大的牌,如果不存在比较关系则输出ERROR。
基本规则:
(1)输入每手牌可能是个子、对子、顺子(连续5张)、三个、炸弹(四个)和对王中的一种,不存在其他情况,由输入保证两手牌都是合法的,顺子已经从小到大排列;
(2)除了炸弹和对王可以和所有牌比较之外,其他类型的牌只能跟相同类型的存在比较关系(如,对子跟对子比较,三个跟三个比较),不考虑拆牌情况(如:将对子拆分成个子);
(3)大小规则跟大家平时了解的常见规则相同,个子、对子、三个比较牌面大小;顺子比较最小牌大小;炸弹大于前面所有的牌,炸弹之间比较牌面大小;对王是最大的牌;

(4)输入的两手牌不会出现相等的情况。

数据范围:字符串长度:




输入描述:

输入两手牌,两手牌之间用"-"连接,每手牌的每张牌以空格分隔,"-"两边没有空格,如 4 4 4 4-joker JOKER。



输出描述:

输出两手牌中较大的那手,不含连接符,扑克牌顺序不变,仍以空格隔开;如果不存在比较关系则输出ERROR。

示例1

输入

4 4 4 4-joker JOKER

输出

joker JOKER
牌数目的多少,注意特殊面值的牌的处理:10,joker,JOKER和J
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    while (getline(cin, str))
    {
        string str1;
        string str2;
        string poke = { "34567891JQKA2j" };
        int num1 = 1,num2 = 1;
        bool str1_flag = true;
        for (int i = 0; i < str.size(); i++)
        {
            if (str1_flag && str[i] != '-')
            {
                str1 += str[i];
                if (str[i] == ' ')
                    num1++;
            }
            else if (str[i] == '-')
            {
                str1_flag = false;
            }
            else
            {
                str2 += str[i];
                if (str[i] == ' ')
                    num2++;
            }
        }
        if (str1 == "joker JOKER" || str2 == "joker JOKER")  //有王炸
        {
            cout << "joker JOKER"<<endl;
            return 0;
        }
        if (num1 == num2)  //牌数相同
        {
            if (str2 == "JOKER")
                cout << str2<<endl;
            else if (str1 == "JOKER")
                cout << str1<<endl;
            else
            {
                for (int i = 0; i < poke.size(); i++)
                {
                    if (str1[0] == poke[i])
                    {
                        cout << str2<<endl;
                        break;
                    }
                    else if (str2[0] == poke[i])
                    {
                        cout << str1<<endl;
                        break;
                    }
                }
            }
        }
        else if (num1 == 4 || num2 == 4)  //有炸弹
        {
            if (num1 == 4)
                cout << str1<<endl;
            else
                cout << str2<<endl;
        }
        else  //啥也不是
            cout << "ERROR"<<endl;
    }
    return 0;
}


编辑于 2022-03-10 16:41:53 回复(0)

比较的时候首先比较类型,如果两副牌的数目相同,那么肯定是相同类型的,在这种情况下再去比较点数,而比较点数的时候大小完全是依靠第一张牌的点数大小决定的;一旦两幅排数目不相同,表示类型出现了差异,这种情况下必须有一方是**,不然就不满足题意的输入了

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;



string find_max(const string& input)
{
    //首先上来看一下有没有王炸
    if(input.find("joker JOKER")!=string::npos)
    {
        return "joker JOKER";
    }
    //分开两幅牌
    string left=input.substr(0,input.find('-'));
    string right=input.substr(input.find('-')+1);//注意+1,不要把“-”放进第二张牌了
    //左牌和右牌的数目=空格数+1;利用算法中的count统计
    size_t left_num=count(left.begin(),left.end(),' ')+1;
    size_t right_num=count(right.begin(),right.end(),' ')+1;

    //如果左面和右面的数量相等,那就说明类型相同
    if(left_num==right_num)
    {
        //首先拿出左面和右面的第一章牌
        string left_first=left.substr(0,left.find(' '));
        string right_first=right.substr(0,right.find(' '));
        //类型相同就比较点数
        string compare("345678910JQKA2jokerJOKER");
        if(compare.find(left_first) > compare.find(right_first))
        {
            //如果左大于有
            return left;
        }
        else
        {
            return right;
        }
    }

    //如果数量不相等,那么有可能是**导致的
    if(left_num==4)
    {
        return left;
    }
    else if(right_num==4)
    {
        return right;
    }
    else//数量不相等,无法比较
    {
        return "ERROR";
    }

}


int main()
{
    string input;//接受输入
    string ret;//返回情况
    while(getline(cin,input))
    {
        ret=find_max(input);
        cout<<ret<<endl;
    }
    return 0;

}
发表于 2021-05-15 20:08:49 回复(0)

优雅永不过时

注释很重要哦

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    // 保存牌面权值 顺序是 10 2 3 4 5 6 7 8 9 ... A ... J K ... Q
    // ... 处权值为0 这样开数组仅仅是为了利用下标 形成映射关系
    short dict[33] = {8, 13, 1, 2, 3, 4, 5, 6, 7};
    dict[32] = 10;
    dict[26] = 11;
    dict[25] = 9;
    dict[16] = 12;
    string str;
    while (getline(cin, str)){
        if (str.find("joker JOKER") != string::npos){
            cout << "joker JOKER" << endl;
            continue;
        }
        int splitPos = str.find('-');
        string A = str.substr(0, splitPos);
        string B = str.substr(splitPos + 1);

        int ACount = count(A.begin(), A.end(), ' ') + 1;
        int BCount = count(B.begin(), B.end(), ' ') + 1;
        // 题目保证输入的牌是合法的 下面的逻辑建立在此基础上
        if (ACount != BCount){
            // AB 牌数不同只会出现在**情况里
            if (ACount == 4) cout << A << endl;
            else if (BCount == 4) cout << B << endl;
            else cout << "ERROR" << endl;
            // 这个 ERROR 其实没必要存在 题目保证输入是合法的
            // 但是 这个垃圾测试用例 有一个 10-3 3
            // 你出单 对家可以出双吗? 这叫合法输入吗?
            // 写这个仅仅是为了测试用例 如果真的合法输入 这里不需要考虑 ERROR
        } else {
            // AB 牌数相同 在合法的情况下 加上顺子输入已经排序
            // 所以 都只需要比较第一位 就好了
            if (dict[A[0] - 49] > dict[B[0] - 49]) cout << A << endl;
            else cout << B << endl;
        }
    }
    return 0;
}


发表于 2021-04-03 22:24:30 回复(0)
"10"为特殊字符,相同数量比较时得这样找s1.substr(0, s1.find(' '))
#include<iostream>
#include<algorithm>
using namespace std;

void handle(string s)
{
    string stand = "345678910JQKA2jokerJOKER";
    if(s.find("joker JOKER")!=string::npos)    {cout<<"joker JOKER"<<endl;return ;}
    int pos =s.find('-');
    string s1 = s.substr(0, pos),s2 = s.substr(pos+1);
    int n1 = count(s1.begin(),s1.end(),' ');
    int n2 = count(s2.begin(),s2.end(),' ');
    if(n1!=n2)
    {
        if(n1==3)    {cout<<s1<<endl;}
        else if(n2==3)    {cout<<s2<<endl;}
        else    {cout<<"ERROR"<<endl;}
    }
    else 
    {
        if(stand.find(s1.substr(0, s1.find(' ')))>stand.find(s2.substr(0,s2.find(' '))))
        {
            cout<<s1<<endl;
        }
        else {cout<<s2<<endl;}
    }
}

int main()
{
    string s;
    while(getline(cin,s))
    {
        handle(s);
    }
    return 0;
}


发表于 2021-03-06 17:38:19 回复(0)
好家伙,代码太简洁明了岂不是很容易被取代,这也太难了吧!
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    const string wang = "joker JOKER";
    const string str = "3 4 5 6 7 8 9 10J Q K A 2 ";
    string s1, s2;
    getline(cin, s1, '-');
    getline(cin, s2);
    int sp1 = count(s1.begin(), s1.end(), ' ');
    int sp2 = count(s2.begin(), s2.end(), ' ');
    if(s1 == wang || s2 == wang) cout << wang;    // 王炸
    else if(sp1 == sp2){                          // 同类比较
        if(str.find(s1.substr(0, 2)) > str.find(s2.substr(0, 2)))
            cout << s1;
        else
            cout << s2;
    }
    else if(sp1 == 3) cout << s1;                // 炸弹(4张)
    else if(sp2 == 3) cout << s2;                // 炸弹(4张)
    else cout << "ERROR";
    return 0;
}

编辑于 2021-01-22 04:46:06 回复(0)
#include <stdio.h>

/* 将输入以"-"为界分隔开,分别存入s1和s2 */
void TwoHandCard(char *s, char *s1, char *s2);

/*  计算牌的类型
    返回值:
    joker JOKER或者JOKER joker  : 0
    单张  : 1
    对子  : 2
    三个  : 3
    **  : 4
    顺子  : 5
 */
int CardType(char *card);

/*  计算同类型牌之间的大小,返回值越大,牌面越大
    3 4 5 6 7 8 9 10 J Q K joker JOKER */
int CardPower(char* card);

int main(void)
{
    char s[100];
    while(gets(s) != 0)
    {
        char s1[20]; // 牌面1
        char s2[20]; // 牌面2
        int t1; // 牌面1的类型
        int t2; // 牌面2的类型
        int p1; // 牌面1的大小
        int p2; // 牌面2的大小
        
        TwoHandCard(s, s1, s2);
        t1 = CardType(s1); // 计算牌面1的类型
        t2 = CardType(s2); // 计算牌面2的类型
        
        if      ((t1 == 0) && (t2 != 0)) { printf("%s\n", s1); } // 牌面1为王炸
        else if ((t1 != 0) && (t2 == 0)) { printf("%s\n", s2); } // 牌面2为王炸
        else if ((t1 == 4) && (t2 != 4)) { printf("%s\n", s1); } // 1为**,2不是
        else if ((t1 != 4) && (t2 == 4)) { printf("%s\n", s2); } // 1不是**,2是
        else if (t1 == t2)
        {  // 牌面相等,比较大小
            p1 = CardPower(s1); // 计算牌面1的大小
            p2 = CardPower(s2); // 计算牌面2的大小
            if (p1 > p2) { printf("%s\n", s1); }
            else         { printf("%s\n", s2); }
        }
        else                             { printf("ERROR\n") ; }
    }
    
    return 0;
}
/* 将输入以"-"为界分隔开,分别存入s1和s2 */
void TwoHandCard(char *s, char *s1, char *s2) {     int j = 0;     int flag = 0;     for (int i = 0; s[i] != '\0'; i++)     {         if (!flag) // 读取牌面1         {             if (s[i] == '-') // 此时牌面1读取完成             {                 s1[j] = '\0';                 flag = 1;                 j = 0;             }             else { s1[j++] = s[i]; }         }         else { s2[j++] = s[i]; } // 读取牌面2     }     s2[j] = '\0'; }


/* 计算牌的类型
返回值:
joker JOKER或者JOKER joker : 0
单张 : 1
对子 : 2
三个 : 3
** : 4
顺子
: 5
*/
int CardType(char *card) {     int cnt = 0;     for (int i = 0; card[i] != '\0'; i++)     {
/* 通过空格数量判断类型 */         if (card[i] == ' ') { cnt++; }     }          if (cnt == 0) { return 1; }     else if (cnt == 1)     {
/*
当有一个空格时,通过前两个字符判断是对子还是王炸
*/         if ((card[0] == 'j') && (card[1] == 'o'))         {              return 0;          }         else if ((card[0] == 'J') && (card[1] == 'O'))         {             return 0;         }         else { return 2; }     }     else if (cnt == 2) { return 3; }     else if (cnt == 3) { return 4; }     else if (cnt == 4) { return 5; } }


int CardPower(char* card) {     if      ((card[0] >= '3') && (card[0] <= '9')) { return (card[0] - '3'); }     else if ((card[0] == '1') && (card[1] == '0')) { return 7; }     else if ((card[0] == 'J') && (card[1] != 'O')) { return 8; }     else if (card[0] == 'Q') { return 9; }     else if (card[0] == 'K') { return 10; }     else if (card[0] == 'A') { return 11; }     else if (card[0] == '2') { return 12; }     else if ((card[0] == 'j') && (card[1] == 'o')) { return 13; }     else if ((card[0] == 'J') && (card[1] == 'O')) { return 14; } }

发表于 2020-08-09 20:38:05 回复(0)
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
map<string, int> M = { {"3",0},{"4",1},{"5",2},{"6",3},{"7",4},{"8",5},{"9",6},{"10",7},{"J",8},{"Q",9},{"K",10},{"A",11},{"2",12},{"joker",13},{"joker",14} };
int main() {
	string str;
	getline(cin, str);
	int index = str.find('-');
	string str1 = str.substr(0, index);
	string str2 = str.substr(index + 1);
	vector<string> vecStr1;
	vector<string> vecStr2;
	int start = 0, stop = start;
	while (stop < str1.length()) {
		if (str1[stop] != ' ') {
			stop++;
		}
		else {
			vecStr1.push_back(str1.substr(start, stop - start));
			start = stop + 1;
			stop = start;
		}
		if (stop == str1.length())
			vecStr1.push_back(str1.substr(start, stop - start));
	}
	start = 0, stop = start;
	while (stop < str2.length()) {
		if (str2[stop] != ' ') {
			stop++;
		}
		else {
			vecStr2.push_back(str2.substr(start, stop - start));
			start = stop + 1;
			stop = start;
		}
		if (stop == str2.length())
			vecStr2.push_back(str2.substr(start, stop - start));
	}
	int lenStr1 = vecStr1.size(), lenStr2 = vecStr2.size();
	if (lenStr1 == lenStr2) {
		if (lenStr1 == 2) {
			if (vecStr1[0] == "joker" || vecStr2[0] == "joker") {
				cout << "joker JOKER" << endl;
				return 0;
			}
		}
		if (lenStr1 < 6) {
			if (M[vecStr1.back()] > M[vecStr2.back()]) {
				for (int i = 0; i < lenStr1; i++) {
					cout << vecStr1[i];
					if (i != lenStr1 - 1)
						cout << " ";
					else
						cout << endl;
				}
			}
			else {
				for (int i = 0; i < lenStr2; i++) {
					cout << vecStr2[i];
					if (i != lenStr2 - 1)
						cout << " ";
					else
						cout << endl;
				}
			}
		}
	}
	else {//如果左右不相等,有一边有**,或者ERROR
		if (str1 == "joker JOKER" || str2 == "joker JOKER") {
			cout << "joker JOKER" << endl;
		}
		else if (lenStr1 == 4) {
			for (int i = 0; i < lenStr1; i++) {
				cout << vecStr1[i];
				if (i != lenStr1 - 1)
					cout << " ";
				else
					cout << endl;
			}
		}
		else if (lenStr2 == 4) {
			for (int i = 0; i < lenStr2; i++) {
				cout << vecStr2[i];
				if (i != lenStr2 - 1)
					cout << " ";
				else
					cout << endl;
			}
		}
		else
			cout << "ERROR" << endl;
	}
	return 0;
}

发表于 2020-08-05 09:11:15 回复(0)
#include<stdio.h>
typedef struct info{
    int type;
    int value;
} info;

info getinfo(char * str){
    char rank[14] = {'3', '4', '5', '6', '7', '8', '9', '1', 'J', 'Q', 'K', 'A', '2', 'j'};
    int cnt = 0;
    for(int i=0; str[i]!='\0'; i++)
        cnt = str[i]==' ' ? cnt + 1 : cnt;
    info res;
    res.type = cnt;
    for(int i=0; i<14; i++){
        res.value = rank[i]==str[0] ? i : res.value;
    }
    if(str[1]=='O') res.value = 14;
    return res;
}

int main(){
    char str[2000] = {0};
    while(scanf("%[^\n]%*c", &str)!=EOF){
        char strA[2000] = {0}, strB[2000] = {0};
        strcat(strA, strtok(str, "-"));
        strcat(strB, strtok(NULL, "-"));
        info infoA = getinfo(strA);
        info infoB = getinfo(strB);
        
        if(infoA.type==1 && infoA.value==13) 
            printf("%s\n", strA);
        else if(infoB.type==1 && infoB.value==13)
            printf("%s\n", strB);
        else if(infoA.type==3 && infoB.type==3){
            if(infoA.value>infoB.value) printf("%s\n", strA);
            else                        printf("%s\n", strB);
        }
        else if(infoA.type==3) printf("%s\n", strA);
        else if(infoB.type==3) printf("%s\n", strB);
        else if(infoA.type==infoB.type){
            if(infoA.value>infoB.value) printf("%s\n", strA);
            else                        printf("%s\n", strB);
        }
        else 
            printf("ERROR\n");
    }
    return 0;
}

发表于 2020-08-02 09:55:18 回复(0)
#include <stdio.h>
#include <string.h>

int cal_space_count(char *s)
{
    int cnt = 0;

    for(int i=0; i<strlen(s); i++)
    {
        if(s[i] == ' ')
            cnt++;
    }
    return cnt;
}

int cal_char_weight(char c)
{
    switch(c){
        case '3'...'9':
            return c - '0';
        case 'J':
            return 11;
        case 'Q':
            return 12;
        case 'K':
            return 13;
        case 'A':
            return 14;
        case '2':
            return 15;
        default:
            return 10;
    }
}

int main()
{
    char s[80];
    while(gets(s)) {
        char *s1, *s2, *tmp;
        int cnt1, cnt2;

        s1 = strtok(s, "-");
        s2 = strtok(NULL, "-");
     //   printf("s1=%s, s2=%s\n", s1, s2);
        if(!strcmp(s1, "joker JOKER") || !strcmp(s2, "joker JOKER")) {
            puts("joker JOKER");
            continue;
        }
        cnt1 = cal_space_count(s1);
        cnt2 = cal_space_count(s2);
       // printf("cnt1=%d, cnt2=%d\n", cnt1, cnt2);
        if(cnt1 != cnt2) {
            if(cnt1 == 3)
                puts(s1);
            else if(cnt2 == 3)
                puts(s2);
            else
                puts("ERROR");
        } else {
            if(cal_char_weight(s1[0]) > cal_char_weight(s2[0]))
                puts(s1);
            else
                puts(s2);
        }
    }
}

发表于 2020-07-26 21:37:27 回复(0)
//数据结构真的是好东西,c++自带的数据结构就很好用了。嘻嘻,自己也不会定义个性化的数据结构。
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int main()
{
    string ss;

    while (getline(cin, ss))
    {
        queue<char> q1;
        queue<char> q2;
        queue<char> q3;
        int l = 0;
        while (ss[l] != '-')
        {
            q1.push(ss[l]);
            l++;
        }
        for (int k = l + 1; k<ss.size(); k++)
        {
            q2.push(ss[k]);
        }
    /*    for(int k=0;k<i;k++)
        {
            char tmp = q1.front();
            cout << tmp;
            q1.pop();
        }
        for (int k = i+1; k<ss.size(); k++)
        {
            char tmp = q2.front();
            cout << tmp;
            q2.pop();
        }*/
        //开始转换
        for (int k = 0; k < ss.size(); k++)
        {
            
            if (ss[k] == 'K') { char tmp = 'Q' + 1; q3.push(tmp); }
            if (ss[k] == 'A') { char tmp = 'Q' + 2; q3.push(tmp); }
            if (ss[k] == '2') {char tmp = 'Q' + 3; q3.push(tmp);    }
            if (ss[k] == '1'&&ss[k + 1] == '0') { char tmp = 'I'; q3.push(tmp); k++; }
             
           if ((ss[k] != 'K')&&(ss[k] != 'A')&&(ss[k] != '2')&&(ss[k] != '1') && (ss[k] != '0'))
                q3.push(ss[k]);
        }
//放到顺序存储的字符数组s中
        int len = q3.size(); 
        //cout << "len=" << len << endl;
        char* s = new char[len];
            for (int k = 0; k < len; k++)
            {
                char tmp = q3.front();
            //    cout << tmp;
                s[k] = tmp;
                q3.pop();
            }
            //cout << endl;
//计算长度
        int    i = 0;
            while (s[i] != '-')
            {
                i++;
            }
        int j = len - (i + 1);
        //cout << "i=" << i << ' ' << "j=" << j << endl;
        /*for (int k=0;k<len;k++)
        {
            cout << s[k];
        }
        cout << endl;*/    
        if (i == 11) { cout << "joker JOKER" << endl; }//王炸
        if (i == 7)//前面为**
        {
            if (j == 11) { cout << "joker JOKER" << endl; }
            if (j == 7)
            {
                if (s[0] > s[i + 1]) {
                    for (int k = 0; k < l; k++) {
                        char tmp;
                        tmp = q1.front();
                        cout << tmp;
                        q1.pop();
                    } cout << endl;
                }
                if (s[0] < s[i + 1]) {
                    for (int k = l + 1; k < ss.size(); k++) {
                        char tmp;
                        tmp = q2.front();
                        cout << tmp;
                        q2.pop();
                    }  cout << endl;
                }
            }
            if (j != 11 && j != 7) {
                for (int k = 0; k<l; k++) {
                    char tmp;
                    tmp = q1.front();
                    cout << tmp;
                    q1.pop();
                }  cout << endl;
            }
        }
        if (i == 1) //单个
        {
            if (j == 11) cout << "joker JOKER" << endl;
            if (j == 7) {
                for (int k = l + 1; k < ss.size(); k++) {
                    char tmp;
                    tmp = q2.front();
                    cout << tmp;
                    q2.pop();
                }  cout << endl;
            }
            if (j == 1)
            {
                if (s[0] > s[i + 1]) {
                    for (int k = 0; k < l; k++) {
                        char tmp;
                        tmp = q1.front();
                        cout << tmp;
                        q1.pop();
                    }  cout << endl;
                }
                if (s[0] < s[i + 1]) {
                    for (int k = l + 1; k < ss.size(); k++) {
                        char tmp;
                        tmp = q2.front();
                        cout << tmp;
                        q2.pop();
                    }  cout << endl;
                }
            }
            if ((j != 11) &&( j != 7) &&( j != 1)) cout << "ERROR" << endl;

        }
        if (i == 3)//对子
        {
            if (j == 11) cout << "joker JOKER" << endl;
            if (j == 7) {
                for (int k = l + 1; k < ss.size(); k++) {
                    char tmp;
                    tmp = q2.front();
                    cout << tmp;
                    q2.pop();
                }  cout << endl;
            }
            if (j == 3)
            {
                //cout << "s[0]" << s[0] << "s[i+1]" << s[i + 1] << endl;                
                if (s[0] > s[i + 1]) {
                    for (int k = 0; k < l; k++) {
                        char tmp;
                        tmp = q1.front();
                        cout << tmp;
                        q1.pop();
                    }  cout << endl;
                }
                if (s[0] < s[i + 1]) {
                    for (int k = l + 1; k < ss.size(); k++) {
                        char tmp;
                        tmp = q2.front();
                        cout << tmp;
                        q2.pop();
                    }  cout << endl;
                }
            }
            if ((j != 11) && (j != 7) && (j != 3)) cout << "ERROR" << endl;
        }
        if (i == 9)//顺子
        {
            if (j == 11) cout << "joker JOKER" << endl;
            if (j == 7) {
                for (int k = l + 1; k < ss.size(); k++) {
                    char tmp;
                    tmp = q2.front();
                    cout << tmp;
                    q2.pop();
                }  cout << endl;
            }
            if (j == 9)
            {
                if (s[0]>s[i + 1]) {
                    for (int k = 0; k<l; k++) {
                        char tmp;
                        tmp = q1.front();
                        cout << tmp;
                        q1.pop();
                    }  cout << endl;
                }
                if (s[0] < s[i + 1]) {
                    for (int k = l + 1; k < ss.size(); k++) {
                        char tmp;
                        tmp = q2.front();
                        cout << tmp;
                        q2.pop();
                    }  cout << endl;
                }
            }
            if ((j != 11) && (j != 7) && (j != 9)) cout << "ERROR" << endl;
        }
        if (i == 5)//3个
        {
            if (j == 11) { cout << "joker JOKER" << endl; }
            if (j == 7) {
                for (int k = l + 1; k < ss.size(); k++) {
                    char tmp;
                    tmp = q2.front();
                    cout << tmp;
                    q2.pop();
                }  cout << endl;
            }
            if (j == 5)
            {
                int flag = 1;
                for (int k = 0; k<i; k = k + 2)
                {
                    char tmmp = s[k];
                    for (int j = k; j < i; j = j + 2)
                        if (tmmp < s[j]) { tmmp = s[j]; s[j] = s[k]; s[k] = tmmp; }
                }

                for (int k = i + 1; k<len; k = k + 2)
                {
                    char tmmp = s[k];
                    for (int j = k; j < len; j = j + 2)
                        if (tmmp < s[j]) { tmmp = s[j]; s[j] = s[k]; s[k] = tmmp; }
                }
                for (int k = 0; k<i; k++)
                {
                    //cout << s[k] <<' '<< s[k + i + 1]<<endl;
                    if (s[k] < s[k + i + 1]) flag = 0;
                }
                //    cout << "flag=" << flag << endl;
                if (flag == 1) {
                    for (int k = 0; k<l; k++) {
                        char tmp;
                        tmp = q1.front();
                        cout << tmp;
                        q1.pop();
                    }  cout << endl;
                }

                if (flag == 0) {
                    for (int k = l + 1; k < ss.size(); k++) {
                        char tmp;
                        tmp = q2.front();
                        cout << tmp;
                        q2.pop();
                    }  cout << endl;
                }
            }
            if ((j != 11) && (j != 7) && (j != 5)) cout << "ERROR" << endl;
        }

    }
    return 0;
}

发表于 2020-07-25 07:06:30 回复(0)
#include<iostream>
(720)#include<string>
#include<vector>
(721)#include<sstream>
#include<unordered_map>
using namespace std;
int main()
{
    unordered_map<char,int>m={{'A',1},{'2',2},{'3',3},{'4',4},{'5',5},{'6',6},{'7',7},{'8',8},{'9',9},{'10',10},{'J',11},{'Q',12},{'K',13}};
    string str;
    
    while(getline(cin,str))
    {
        vector<string>vec1;
        vector<string>vec2;
        string str1,str2;
        string str11,str22;
        int len;
        len=str.length();
   
        int j=str.find('-');
        str1=str.substr(0,j);
        str2=str.substr(j+1);
        if(str1=="joker JOKER"||str2=="joker JOKER")
        {
            cout<<"joker JOKER"<<endl;
        }
        else
               {
                stringstream ss1(str1);
           while(getline(ss1,str11,' '))
             {
            vec1.push_back(str11);
               }
           stringstream ss2(str2);
        while(getline(ss2,str22,' '))
                  {
            vec2.push_back(str22);
                   }
        int len1;
        int len2;
        len1=vec1.size();
        len2=vec2.size();
   
         if(len1==len2)
          {
            if(m[vec1[0][0]]>m[vec2[0][0]])
            {
                cout<<str1<<endl;
            }
            else
             {
                cout<<str2<<endl;
            }
          }
           else if(len1!=len2&&len1==4)
          {
              cout<<str1<<endl;
          }
          else if(len1!=len2&&len2==4)
          {
              cout<<str2<<endl;
          }
          else
             cout<<"ERROR"<<endl;
       }
        
        
    }
    return 0;
}
通过90%,求助。

编辑于 2020-04-10 18:22:16 回复(0)
#include <iostream>
(720)#include <string>
#include <cstring>
(803)#include <vector>
#include <algorithm>
using namespace std;
bool compareBigDigit(const string& first,const string& second)
{
    vector<string> sequence = {"3","4","5","6","7","8","9","10","J","Q","K","A","2","joker","JOKER"};
    auto firstIter = find(sequence.begin(),sequence.end(),first);
    auto secondIter = find(sequence.begin(),sequence.end(),second);
    if(distance(firstIter,secondIter)<0)
    {
        return true;
    }
    else
    {
        return false;
    }
    
}
vector<string> getCardsContent(string input)
{
    vector<string> output;
    char *cardNumber = strtok((char*)input.c_str()," ");
    while(cardNumber!=NULL)
    {
        output.push_back(cardNumber);
        cardNumber = strtok(NULL," ");
    }
    return output;
}
int judgeCardsType(const vector<string> &cardsVector)
{    
    int cardsLength = cardsVector.size();
    switch(cardsLength)
    {
        case 1:
            return 1;
        case 2:
            {
                if(cardsVector[0]=="joker" ||cardsVector[0]=="JOKER")
                {
                    return 6;
                }
                else
                {
                    return 2;
                }
            }
        case 3:
            return 3;
        case 4:
            return 4;
        case 5:
            return 5;
        default:
            return 0;
    }
}
int main()
{
    string input;
    while(getline(cin,input))
    {
        int linkposition = input.find('-');
        string first = input.substr(0,linkposition);
        string second = input.substr(linkposition+1);
        vector<string> firstCards = getCardsContent(first);
        vector<string> secondCards = getCardsContent(second);
        if(judgeCardsType(firstCards) == judgeCardsType(secondCards))
        {
            if(compareBigDigit(firstCards[0],secondCards[0]))
            {
                cout<<first<<endl;
            }
            else
            {
                cout<<second<<endl;
            }
        }
        else 
        {
            if(judgeCardsType(firstCards) == 6)
            {
                cout<<first<<endl;
            }
            else if(judgeCardsType(secondCards) == 6)
            {
                cout<<second<<endl;
            }
            else if(judgeCardsType(firstCards)==4)
            {
                cout<<first<<endl;
            }
            else if(judgeCardsType(secondCards) == 4)
            {
                cout<<second<<endl;
            }
            else
            {
                cout <<"ERROR"<<endl;
            }
        }        
    }
    return 0;
}


发表于 2020-04-09 23:22:25 回复(0)
输入由用例保证,难度降低了些。
#include <map>
(747)#include <string>
#include <vector>
(721)#include <iostream>
using namespace std;
int main(){
    string ins;
    map<string,int> weight;
    weight["3"]=1;   weight["4"]=2;   weight["5"]=3;   weight["6"]=4;  weight["7"]=5;  
    weight["8"]=6;   weight["9"]=7;   weight["10"]=8;  weight["J"]=9;  weight["Q"]=10; 
    weight["K"]=11;  weight["A"]=12;  weight["2"]=13;
    while(getline(cin,ins)){
		vector<string> vs= { "" };
		int j = 0, k;
		bool f=false;
		for (int i = 0; i < ins.size(); i++) {
			if (isalnum(ins[i])) {
				if (f) {
					vs.push_back("");
					j++;
				}
				vs[j] += ins[i];
				f = false;
			}
			else {
				f = true;
				if (ins[i] == '-')  k = j+1;
			}
		}
		vector<string> s1(vs.begin(), vs.begin() + k), s2(vs.begin() + k, vs.end());
        if(s1.size()==2&&s1[0]=="joker"&&s1[1]=="JOKER"){
            f=true; k=1;
        }
        else if(s2.size()==2&&s2[0]=="joker"&&s2[1]=="JOKER"){
            f=true; k=2;
        }
        else{
            if(s1.size()==s2.size()){
                f=true;
                if(weight[s1[0]]>weight[s2[0]]) k=1;
                else            k=2;
            }
            else{
                if(s1.size()==4){
                    f=true; k=1;
                }
                else if(s2.size()==4){
                    f=true; k=2;
                }
                else
                    f=false;
            }
        }
        if(!f) cout<<"ERROR";
        else{
            if(k==1)
                for(string s:s1)
                    cout<<s<<' ';
            else if(k==2)
                for(string s:s2)
                    cout<<s<<' ';
        }
    }
}


发表于 2020-03-09 22:00:57 回复(0)
我吐了,你呢
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,sub[2];
    string card[15]={"3","4","5","6","7","8","9","10","J","Q","K","A","2","joker","JOKER"};
    int cnt[2];//牌的数目
    string val[2];//牌面值
    int div;//两手牌的分割点
    while(getline(cin,s)){
        div=0,cnt[0]=1,cnt[1]=1;
        for(char c:s){
            if(c=='-')break;
            div++;
        }
        sub[0]=s.substr(0,div);
        sub[1]=s.substr(div+1);
        for(int i=0;i<2;i++){
            if(sub[i]=="joker JOKER")goto end;
            int k;
            for(k=0;k<sub[i].length();k++){
                if(isspace(sub[i][k]))break;
            }
            val[i]=sub[i].substr(0,k);
            for(char c:sub[i]){
                if(isspace(c)){
                    cnt[i]++;
                }
            }
        }
        if(cnt[0]!=cnt[1]&&(cnt[0]!=4&&cnt[1]!=4))cout<<"ERROR"<<endl;
        else if(cnt[0]==4||cnt[1]==4){
            if(cnt[0]==4&&cnt[1]==4){
                cout<<(find(&card[0],&card[15],val[0])>find(&card[0],&card[15],val[1])?sub[0]:sub[1])<<endl;
            }else if(cnt[0]==4)cout<<sub[0]<<endl;
            else cout<<sub[1]<<endl;
        }else{
            cout<<(find(&card[0],&card[15],val[0])>find(&card[0],&card[15],val[1])?sub[0]:sub[1])<<endl;
        }
        continue;
        end:
        cout<<"joker JOKER"<<endl;
    }
    return 0;
}


发表于 2020-02-21 22:43:46 回复(0)

个人感觉自己的想法简单点,高赞看不懂

  1. 牌数量相同的可以直接比较,输出大的就行
  2. 不相同的分为都是炸,一个是炸,两个都不是炸共三种情况,都是炸也就是直接比较输出大的,一个是炸直接输出炸的那个,两个都不是炸输出ERROR

思路就这么简单!

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
vector<string> Pocker{"3","4","5","6","7","8","9","10","J","Q","K","A","2",
                     "joker","JOKER"};
bool IsBomb(vector<string> &pai)
{
    if(pai.size() == 2)//如果只有两张必须得是双王
    {
        if(pai[0] == "joker" || pai[0] == "JOKER")
            return true;
        else
            return false;
    }
    else if(pai.size() == 4) //不然只能是四张
    {
        return true;
    }
    else
        return false;
}
void Compare(vector<string> &first, vector<string> &second)
{
    auto p1 = find(Pocker.begin(), Pocker.end(), first[0]);
    auto p2 = find(Pocker.begin(), Pocker.end(), second[0]);
    if(p1 > p2)
    {
        for(int i=0; i<first.size()-1; ++i)
            cout << first[i] << " ";
        cout << first[first.size()-1] << endl;
    }
    else
    {
        for(int i=0; i<second.size()-1; ++i)
            cout << second[i] << " ";
        cout << second[second.size()-1] << endl;
    }
}
void Output(vector<string> &pai)
{
    for(int i=0; i<pai.size()-1; ++i)
        cout << pai[i] << " ";
    cout << pai[pai.size()-1] << endl;
}
void getBigger(string &input)
{
    string input1, input2, temp;
    vector<string> first, second;
    int pos = input.find('-');
    input1 = input.substr(0, pos);
    input2 = input.substr(pos+1);
    stringstream ss;
    ss << input1;
    while(ss >> temp)
    {
        first.push_back(temp);
    }
    ss.clear(); ss << input2;
    while(ss >> temp)
        second.push_back(temp);
    if(first.size() == second.size())
        Compare(first, second);
    else//牌数目不相同那肯定是得有一个是炸弹,不然输出ERROR
    {
        if(IsBomb(first))//第一个是炸弹
        {
            if(IsBomb(second))//第二个也是炸弹,则直接比较输出
                Compare(first, second);
            else
                Output(first);
        }
        else    //第一个不是炸弹
        {
            if(IsBomb(second))//第二个是炸弹
                Output(second);
            else    //两个都不是炸弹
                cout << "ERROR" << endl;
        }
    }
}
int main()
{
    string input;
    while(getline(cin, input))
    {
        getBigger(input);
    }
}


发表于 2020-02-08 21:06:16 回复(3)
#include<iostream>
#include<string>
using namespace std;
void Cmp_puke(const string& str)
{
    string str1;
    string str2;
    size_t pos = str.find('-');
    if(string::npos==pos)
    {
        return;
    }
    else
    {
        str1=str.substr(0,pos);
        str2=str.substr(pos+1);
    }
    int i=0;
    string copys1=str1;
    string copys2=str2;
    while(string::npos != (pos=str1.find('1',i)))
    {
        str1[pos]='=';
        str1.erase(pos+1,1);
        i=pos+1;
    }
    i=0;
    while(string::npos != (pos=str2.find('1',i)))
    {
       str2[pos]='=';
        str2.erase(pos+1,1);
         i=pos+1;
    }
       int len1=str1.size();
    int len2=str2.size();
    if(len1==1)
    {
        if(len2==1&&str1<str2)
        {
            cout<<copys2<<endl;
            return;
        }
        else if(len2==1&&str1>str2)
        {
            cout<<copys1<<endl;
            return;
        }
    }
    else if(len1==3)
    {
        if(len2==3 && str1<str2)
            {
            cout<<copys2<<endl;
            return;
            }
         else if(len2==3 && str1>str2)
            {
            cout<<copys1<<endl;
            return;
            }
    }
     else if(len1==5)
    {
        if(len2==5&& str1<str2)
            {
            cout<<copys2<<endl;
            return;
            }
         else if(len2==5&& str1>str2)
             {
            cout<<copys1<<endl;
            return;
            }
         else if(len2==3&&str1>str2)
              {
            cout<<copys1<<endl;
            return;
            }
            else if(len2==3&& str1<str2)
             {
            cout<<copys2<<endl;
            return;
            }
    }
    else if(len1==9)
    {
        if(len2==9&& str1<str2)
             {
            cout<<copys2<<endl;
            return;
            }
         else if(len2==9&& str1>str2)
           {
            cout<<copys1<<endl;
            return;
            }
    }
    else if(len1==7)
    {
        if(len2==7 && str1<str2)
             {
            cout<<copys2<<endl;
            return;
            }
         else if(len2==7 && str1>str2)
            {
            cout<<copys1<<endl;
            return;
            }
        else if(len2!=7&&str2[0]!='j')
        {
              cout<<copys1<<endl;
                return;
        }
    }
    if(str1[0]=='j')
         {
            cout<<copys1<<endl;
            return;
            }
    if(str2[0]=='j')
          {
            cout<<copys2<<endl;
            return;
          }
    else 
        cout<<"ERROR"<<endl;
 }
int main()
{
    string str;
    getline(cin,str);
    Cmp_puke(str);
    return 0;
}




看我的方法烦不烦?难死我了啊 啊啊啊啊   啊啊啊啊 啊啊啊啊 啊啊  啊 
发表于 2019-11-24 23:43:27 回复(0)
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<string> split(string str, const char c){//字符串分割函数
    vector<string> sstr;
    int pos = 0;
    while (pos < str.length()){
        int end;
        for (end = pos; str[end] != c && end < str.length(); end++);
        sstr.push_back(str.substr(pos, end - pos));
        pos = end + 1;
    }
    return sstr;
}
int main(){
    string inputs;
    vector<int>cards = { 3 + '0', 4 + '0', 5 + '0', 6 + '0', 7 + '0', 8 + '0', 9 + '0', 10 + '0', 'J', 'Q', 'K', 'A', 2 + '0' };
    vector<int> cmp(128, 0);
    char c = 10 + '0';//将“10”转成字符c
    for (int i = 1; i < cards.size(); i++){
        cmp[cards[i]] = cmp[cards[i - 1]] + 1;
    }
    
    while (getline(cin, inputs)){
        vector<string> twoCard = split(inputs, '-');
        //考虑对王情况
        if (twoCard[0] == "joker JOKER" || twoCard[1] == "joker JOKER"){
            cout << "joker JOKER" << endl;
            continue;
        }
        else if (twoCard[0] == "JOKER joker" || twoCard[1] == "JOKER joker"){
            cout << "JOKER joker" << endl;
            continue;
        }
        vector<string> firstCard = split(twoCard[0], ' ');
        vector<string> secondCard = split(twoCard[1], ' ');
        //考虑非对王的炸的情况
        if (firstCard.size() == 4 || secondCard.size() == 4){
            if (firstCard.size() != 4){
                cout << twoCard[1] << endl;
                continue;
            } else if(secondCard.size() != 4){
                cout << twoCard[0] << endl;
                continue;
            }
            else{//两遍都是炸
                firstCard[0] = firstCard[0] == "10" ? ("" + c) : firstCard[0];//处理10这张牌
                secondCard[0] = secondCard[0] == "10" ? ("" + c) : secondCard[0];//处理10这张牌
                if (cmp[firstCard[0][0]] > cmp[secondCard[1][0]]){
                    cout << twoCard[0] << endl;//谁的炸大就打印谁的牌
                    continue;
                }
                else{
                    cout << twoCard[1] << endl;
                    continue;
                }
            }
        }
        //考虑单张牌的情况,要考虑单张大小王的情况
        else if (firstCard.size() == 1 && secondCard.size() == 1){
            if (twoCard[0] == "JOKER" || twoCard[1] == "JOKER"){//大王
                cout << "JOKER" << endl;
                continue;
            }
            else if (twoCard[0] == "joker" || twoCard[1] == "joker"){//没有大王有小王
                cout << "joker" << endl;
                continue;
            }
            else{//没有大小王
                firstCard[0] = firstCard[0] == "10" ? ("" + c) : firstCard[0];//处理10这张牌
                secondCard[0] = secondCard[0] == "10" ? ("" + c) : secondCard[0];//处理10这张牌
                if (cmp[firstCard[0][0]] > cmp[secondCard[0][0]]){
                    cout << twoCard[0] << endl;//谁的大就打印谁的牌
                    continue;
                }
                else{
                    cout << twoCard[1] << endl; 
                    continue;
                }
            }        
        }
        else if ((firstCard.size() == 2 && secondCard.size() == 2) || 
            (firstCard.size() == 3 && secondCard.size() == 3) ||
            (firstCard.size() == 5 && secondCard.size() == 5)){//一对数,或者三张或者5张没有大小王,没有炸
            firstCard[0] = firstCard[0] == "10" ? ("" + c) : firstCard[0];//处理第一张是10的这张牌
            secondCard[0] = secondCard[0] == "10" ? ("" + c) : secondCard[0];//处理第一张是10的这张牌
            if (cmp[firstCard[0][0]] > cmp[secondCard[0][0]]){
                cout << twoCard[0] << endl;//谁的大就打印谁的牌
                continue;
            }
            else{
                cout << twoCard[1] << endl;
                continue;
            }
        }
        else{
            cout << "ERROR" << endl;
        }
    }
    return 0;
}

发表于 2019-07-21 15:39:50 回复(1)
//我觉得前几个C++判断输赢的条件太麻烦了,我这个判断输赢逻辑要简单很多。
#include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
using namespace std;

vector<string> table = {"3","4","5","6","7","8","9","10","J","Q","K","A","2","joker","JOKER"}; 

vector<string> split(string s, char c){
    vector<string> res;
    stringstream ss(s);
    string tmp;
    while(getline(ss, tmp, c)){
        res.push_back(tmp);
    }
    return res;
}

int judgePoker(vector<string> vs){
    if(vs.size() == 1)
        return 1;//个子
    if(vs.size() == 2 ){
        if(vs[0] == "joker" || vs[1] == "joker")
            return 6;
        else
            return 2;//对子
    }
    if(vs.size() == 3)
        return 3;//三个
    if(vs.size() == 4)
        return 4;//**
    if(vs.size() == 5)
        return 5;//顺子
    return 0;
}

void judgeWin(int& win, vector<string> vs1, vector<string> vs2){
    int j1 = judgePoker(vs1);
    int j2 = judgePoker(vs2);
    
    if(j1 == j2){
        if(find(table.begin(), table.end(), vs1[0]) > find(table.begin(), table.end(), vs2[0]))
            win = 1;
        else
            win = 2;
    }
    else{
        if(j1 == 6 || j2 == 6){
            if(j1 == 6)
                win = 1;
            else
                win = 2;
        }
        else if(j1 == 4 || j2 == 4){
            if(j1 == 4)
                win = 1;
            else
                win = 2;
        }
        else
            win = 0;
    }
}

void PrintWin(vector<string> vs){
    int i = 0;
    for(; i < vs.size(); ++i){
        cout << vs[i] << " ";
    }
    //cout << endl;
}

int main(){
    string s;
    while(getline(cin,s)){
        vector<string> vec = split(s, '-');
        vector<string> poker1 = split(vec[0], ' ');
        vector<string> poker2 = split(vec[1], ' ');
        
        int win = -1;
        judgeWin(win, poker1, poker2);
        
        if(win == 1)
            PrintWin(poker1);
        if(win == 2)
            PrintWin(poker2);
        if(win == 0)
            cout << "ERROR" << endl;
    }
    
    return 0;
}


发表于 2018-12-22 18:07:02 回复(0)
#include <iostream>
#include <string>
using namespace std;

int initial(char char_s) {
    switch(char_s)  {
        case '3' : return 1;
        case '4' : return 2;
        case '5' : return 3;
        case '6' : return 4;
        case '7' : return 5;
        case '8' : return 6;
        case '9' : return 7;
        case '1' : return 8; 
        case 'J' : return 9;
        case 'Q' : return 10;
        case 'K' : return 11;
        case 'A' : return 12;
        case '2' : return 13;
    }
    return 0;
}

int range_str(string str_in) {
    int str_len = str_in.length();
    int temp_strat = 0;
    while(str_in.find("10", temp_strat) != string :: npos) {
        str_len --;
        temp_strat = str_in.find("10", temp_strat) + 1;
    }
    if(str_in == "joker JOKER")
        return 1;
    else if(str_len == 7)
        return 2;
    else if(str_len == 5)
        return 3;
    else if(str_len == 9)
        return 4;
    else if(str_len == 3)
        return 5;
    else
        return 6;
}

void swap(string &str1, string &str2) {
    string str_s = str1;
    str1 = str2;
    str2 = str_s;
}

string compare_result(string str1, string str2) {
    if(range_str(str2) < range_str(str1))
        swap(str1, str2);
    if(range_str(str1) == 1)
        return str1;
    else if (range_str(str1) == 2 && range_str(str2) != 2)
        return str1;
    else if (range_str(str1) == range_str(str2)) {
        if(initial(str1[0]) > initial(str2[0]))
            return str1;
        else
            return str2;
    } else {
        return "ERROR";
    }
}

int main() {
    string str_s;
    while(getline(cin, str_s)) {
        string str_1 = str_s.substr(0, str_s.find('-'));
        string str_2 = str_s.substr(str_s.find('-') + 1, str_s.length() - str_s.find('-') - 1);
        cout << compare_result(str_1, str_2) << endl;
    }
    system("pause");
    return 0;
}
//根据字符串长度设置等级
//不同的等级之间如何比较
编辑于 2018-11-02 00:29:10 回复(0)
//加入了检查出牌合法的情况,写了一半发现好像不需要……
#include <bits/stdc++.h>
using namespace std;
string hel = "345678910JQKA2jokerJOKER";
vector<string> split(string s)
{
    vector<string> out;
    s += ' ';
    int l = s.length();
    for (int i = 0; i<l; i++)
    {
        int j = i;
        while (j<l&&s[j] != ' ')j++;
        out.push_back(s.substr(i, j - i));
        i = j;
    }
    return out;
}
int core(vector<string>& n1, vector<string>& n2)
{
    int sz1 = n1.size();
    int sz2 = n2.size();
    if (sz1==sz2)
    {
        if ((sz1 == 3 && (n1[0] == n1[1] &&n1[1]== n1[2]) && (n2[0] == n2[1] &&n2[1]== n2[2])) ||
            sz1 == 1 ||
            (sz1 == 2 && (n1[0] == n1[1]) && (n2[0] == n2[1])) ||
            (sz1 == 4 && (n1[0] == n1[1] && n2[1] == n2[2] && n1[2] == n1[3])&&(n2[0] == n2[1] &&n2[1]==n2[2]&& n2[2] == n2[3])))
                return hel.find(n1[0])>hel.find(n2[0]);
        if (sz1 == 5)
        {

            string tp1, tp2;
            for (int i = 0; i<5; i++)
            {
                tp1 += n1[i];
                tp2 += n2[i];
            }
            if (hel.find(tp1) == -1 || hel.find(tp2) == -1)return -1;
            return hel.find(n1[0])>hel.find(n2[0]);
        }
        return -1;
    }
    else 
    {
        if (sz1 == 4 && (n1[0] == n1[1] && n1[1] == n1[2] && n1[2] == n1[3]))
             return 1;
        if (sz2 == 4 && (n2[0] == n2[1] && n2[1] == n2[2]&& n2[2] == n2[3]))
             return 0;
    }
    return -1;
}
int main()
{
    string s;
    while (getline(cin, s))
    {
        string s1, s2;
        int id = s.find('-');
        s1 = s.substr(0, id);
        s2 = s.substr(id + 1);
        if(s1=="joker JOKER"||s2=="joker JOKER"){cout<<"joker JOKER"<<endl;continue;}

        vector<string> n1 = split(s1), n2 = split(s2);
        int sig = core(n1, n2);
        if (sig == 1)
            cout << s1 << endl;
        else if (sig == 0)
            cout << s2 << endl;
        else
            cout << "ERROR" << endl;
    }
}
发表于 2018-09-08 10:31:07 回复(0)