# 除了炸弹和大小王需要单独比较,其他的可以根据第一个索引判断大小 def daxiao(s,t): xl = ['3','4','5','6','7','8','9','10','J','Q','K','A','2','joker','JOKER'] if len(s) == len(t): if xl.index(s[0])>xl.index(t[0]): print(' '.join(s)) else: print(' '.join(t)) elif s == ['joker','JOKER']&nbs***bsp;t == ['joker','JOKER']: print( ' '.join(['joker','JOKER'])) elif len(s) == 4 and t != ['joker','JOKER']: print(' '.join(s)) elif len(t) == 4 and s != ['joker','JOKER']: print(' '.join(t)) else: print('ERROR') lis = input().split('-') s = lis[0].split(' ') t = lis[1].split(' ') daxiao(s,t)
#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; }
# 2022/3/12 16:03 - 时间 # PyCharm - 当前集成开发环境 # 思路 : 类型一样和类型不一样的 power = ["3","4","5","6","7","8","9","10","J","Q","K","A","2","joker","JOKER"] while True: try: a,b = input().split('-') sas = a.split() sbs = b.split() # 类型一样 if len(sas) == len(sbs): if power.index(sas[0])>power.index(sbs[0]): print(a) else: print(b) #类型不一样 else: # 有王炸直接输出王炸 if a =="joker JOKER"&nbs***bsp;b =="joker JOKER": print("joker JOKER") # a有炸弹 elif len(sas)==4: print(a) # b有炸弹 elif len(sbs)==4: print(b) #其他类型,无法比较 else: print("ERROR") except: break
import java.util.HashMap; import java.util.Map; import java.util.Scanner; /** * @author letere * @create 2021-11-05 18:14 */ public class Main { public static Map<String, Integer> poke = getData(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String[] strArr = sc.nextLine().split("-"); System.out.println(compare(strArr[0], strArr[1])); } } // 比较牌大小,返回大牌 public static String compare(String str1, String str2) { int level1 = getLevel(str1.split(" ")); int level2 = getLevel(str2.split(" ")); // 不存在比较关系 if (level1 / 100 != level2 / 100 && level1 / 100 != 5 && level2 / 100 != 5) { return "ERROR"; } else { // 存在比较关系,直接比较大小 if (level1 - level2 > 0) { return str1; } return str2; } } // 计算牌的大小(个子以100开头,对子200,三张300,顺子400,**500,王炸599) public static int getLevel(String[] arr) { // 个子 if (arr.length == 1) { return 100 + poke.get(arr[0]); } // 对子(王炸) if (arr.length == 2) { if (!arr[0].equals("joker") && !arr[0].equals("JOKER")) { return 200 + poke.get(arr[0]); } return 599; } // 三张 if (arr.length == 3) { return 300 + poke.get(arr[0]); } // 顺子 if (arr.length == 5) { return 400 + poke.get(arr[0]); } // ** if (arr.length == 4) { return 500 + poke.get(arr[0]); } return 0; } // 获取牌对应的优先级 public static Map<String, Integer> getData() { Map<String, Integer> map = new HashMap<>(); map.put("3", 3); map.put("4", 4); map.put("5", 5); map.put("6", 6); map.put("7", 7); map.put("8", 8); map.put("9", 9); map.put("10", 10); map.put("J", 11); map.put("Q", 12); map.put("K", 13); map.put("A", 14); map.put("2", 15); map.put("joker", 16); map.put("JOKER", 17); return map; } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNextLine()){ String S = in.nextLine(); // 输入手牌 String s[] = S.split("-"); // s[0]:左手牌,s[1]:右手牌 String s1[] = s[0].split(" "), s2[] = s[1].split(" "); // 拆分出每手牌的牌面,目的是得到每手牌的张数 int n1 = s1.length, n2 = s2.length; // 每手牌的张数 //******************************************************************** 有王炸的情况 if(n1==2 || n2==2){ if(n1==2 && s[0].contains("joker") && s[0].contains("JOKER")){ // 左手牌有王炸,直接输出 System.out.println(s[0]); continue; } if(n2==2 && s[1].contains("joker") && s[1].contains("JOKER")){ // 右手牌有王炸,直接输出 System.out.println(s[1]); continue; } } //*************************************************************** 有4连炸的情况 if(n1==4 || n2==4){ if(n1 == n2){ // 两手牌都是**,输出大的那一个 String t = s[0].charAt(0)>s[1].charAt(0) ? s[0]:s[1]; System.out.println(t); continue; }else if(n1 == 4){ // 左手牌有**,直接输出 System.out.println(s[0]); continue; }else if(n2 == 4){ // 右手牌有**,直接输出 System.out.println(s[1]); continue; } } //*************************************************************** 非**的情况 if(n1 == n2){ // 同类型才能比较,即每手牌的张数相等 // !!注意:此处需要比较每手牌的最后一张牌面(即最后一个字符) // 若比较第一个字母,则(10 J Q K A)不能正常比较,会用'1'去和其他顺子比较 // 例(3 4 5 6 7-10 J Q K A),会发生'3'>'1'判定左手牌大,判断错误,所以需要判断最后一个字母 String t = s[0].charAt(s[0].length()-1)>s[1].charAt(s[1].length()-1) ? s[0]:s[1]; // !!但是这个也不严谨,对于(3 4 5 6 7-6 7 8 9 10)也会判断错误,不过可以通过该题的所有案例,存在BUG System.out.println(t); }else{ // 非同类型不能比较 System.out.println("ERROR"); } } } }
import java.util.*; public class Main{ public static void main(String[] args){ //本题不考虑拆牌,输入要不是是对子,就是对子,或者顺子。。。,不会有对子加对子这种 Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String str = sc.nextLine(); String[] cards = str.split("-"); String[] card1 = cards[0].split(" "); String[] card2 = cards[1].split(" "); int[] card_1 = changeCard(card1); int[] card_2 = changeCard(card2); int result = solve(card_1,card_2); if(result == 0){ System.out.println("ERROR"); }else if(result == 1){ System.out.println(cards[0]); }else{ System.out.println(cards[1]); } } } //比较大小 1表示card1大,2表示card2大 private static int solve(int[] card1,int[] card2){ int sym1 = check(card1);//手牌的模式 int sym2 = check(card2); //输入的两手牌不会出现相等的情况,且已经升序排列 if(sym1 == sym2){//有这几种情况:两手都是 单只,对子,顺子、三个、** 只要比较最小的牌(最前的牌) return card1[0]>card2[0] ? 1:2; }else{ //有这几种情况: 要不不能比较,要不有**或者大小王 if(sym1 == 6 || sym2 == 6){//有大小王 return sym1 == 6 ? 1:2; } if(sym1 == 4 || sym2 == 4){//有** return sym1 == 4 ? 1:2; } return 0;//0表示异常,两手牌不能比较 } } //判断手牌的模式 private static int check(int[] card){ int len = card.length; if(len == 1){ return 1;//单张 }else if(len == 2 && card[0] == 16 && card[1] == 17){ return 6;//对王 }else if(len == 2 && card[0] == card[1]){ return 2;//对子 }else if(len == 3){ return 3;//三张 }else if(len == 5){ return 5;//顺子 }else if(len == 4){ return 4;//** } return -1; } //改变为纯数字 private static int[] changeCard(String[] card){ int[] temp = new int[card.length]; int index = 0; for(String s : card){ switch(s){ case "J": temp[index] = 11; break; case "Q": temp[index] = 12; break; case "K": temp[index] = 13; break; case "A": temp[index] = 14; break; case "2": temp[index] = 15; break; case "joker": temp[index] = 16; break; case "JOKER": temp[index] = 17; break; default : temp[index] = Integer.parseInt(s); } index++; } return temp; } }
import java.util.*; public class Main { private static Map<String, Integer> map = new HashMap<String, Integer>() { { put("3", 3); put("4", 4); put("5", 5); put("6", 6); put("7", 7); put("8", 8); put("9", 9); put("10", 10); put("J", 11); put("Q", 12); put("K", 13); put("A", 14); put("2", 15); put("joker", 16); put("JOKER", 17); } }; public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); // 如果字符串包含王炸,直接输出,排除这种情况 if (str.contains("joker JOKER")) { System.out.println("joker JOKER"); } else { String[] strs = str.split("-"); String[] poker1 = strs[0].split(" "); String[] poker2 = strs[1].split(" "); int len1 = poker1.length; int len2 = poker2.length; // 同类型的牌对比,通过总和的大小来对比 if (len1 == len2) { int sum1 = 0; int sum2 = 0; for (String s1 : poker1) { sum1 += map.get(s1); } for (String s2 : poker2) { sum2 += map.get(s2); } System.out.println(sum1 > sum2? strs[0] : strs[1]); // 不同类型的牌,如果有**输出**,没有则报 ERROR } else { if (len1 == 4) { System.out.println(strs[0]); } else if (len2 == 4) { System.out.println(strs[1]); } else { System.out.println("ERROR"); } } } } }
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String[] jiben = {"3","4","5","6","7","8","9","M","J","Q","K","A","2"}; Map<String, Integer> sortMap = new HashMap<>(); for(int i = 0; i<jiben.length; i++){ sortMap.put(jiben[i], i); } String ls = scanner.nextLine(); String lsl = ls; String[] pp = lsl.split("-"); if(ls.contains("10")){ ls = ls.replace("10","M"); } ls = ls.replaceAll(" ", ""); String[] p = ls.split("-"); int lengthP0 = p[0].length(); int lengthP1 = p[1].length(); if(p[1].contains("joker")|| p[0].contains("joker")){ System.out.println("joker JOKER"); }else if(lengthP1 == lengthP0){ if(lengthP0 != 3){ if(sortMap.get(p[0].substring(0,1))>sortMap.get(p[1].substring(0,1))){ System.out.println(pp[0]); }else { System.out.println(pp[1]); } }else { //找出两手牌三个中最大的比较 int p0Max=0; int p1Max=0; for(int i = 1; i<4; i++){ p0Max = Math.max(p0Max, sortMap.get(p[0].substring(i-1,i))); p1Max = Math.max(p1Max, sortMap.get(p[1].substring(i-1,i))); } if(p0Max>p1Max){ System.out.println(pp[0]); }else { System.out.println(pp[1]); } } }else { if(p[0].length()==4){ System.out.println(pp[0]); }else if (p[1].length()==4){ System.out.println(pp[1]); }else { System.out.println("ERROR"); } } } } }
# 使用字典更加高效一点:使用字典来定义牌面值的大小 # 先判断是否有对王,有则输出对王 # 然后判断双方牌数是否相同,牌数相同时,按牌面值比,输出第一位较大的(包含**和**的比较) # 当双方牌数不一样时,然后判断其中一方是否有**,有则输出**。否则,无法比较,输出ERROR。 while True: try: D = {'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} a, b = input().split('-') s1, s2 = a.split(), b.split() if a == 'joker JOKER' or b == 'joker JOKER': print('joker JOKER') elif len(s1) == len(s2): print(a if D[s1[0]]>D[s2[0]] else b) elif len(s1) == 4: print(a) elif len(s2) == 4: print(b) else: print('ERROR') except: break
def bomb(s): s = s.split() if len(s) == 4 and s[0] == s[1] == s[2] == s[3]: return True else: return False def tranform(s): s = s.replace('10', 'a') s = s.replace('J', 'b') s = s.replace('Q', 'c') s = s.replace('K', 'd') s = s.replace('A', 'e') s = s.replace('2', 'f') return s while 1: try: s = input() S1, S2 = s.split('-') if 'joker JOKER' in s: print('joker JOKER') else: if bomb(S1) and not bomb(S2): print(S1) elif not bomb(S1) and bomb(S2): print(S2) elif bomb(S1) and bomb(S2): print(S1 if tranform(S1) > tranform(S2) else S2) else: if len(S1.split()) != len(S2.split()): print('ERROR') else: print(S1 if tranform(S1) > tranform(S2) else S2) except: break
#include <iostream> #include <string> #include <vector> #include <sstream> #include <algorithm> using namespace std; //思路: //通过"-"切割字符串,得到两个串 //通过" ",分别切割字符串,得到两个数组 //通过数组size 设定 flag 判断 输入的是 个子,对子,三子,**,顺子 //建立一个由3 -- JOKER,从小到达的数组,作为判断依据 //写入正常逻辑 int judge(vector<string> v) { int flag = 0; if(v.size() == 1) flag = 1;//个子 else if(v.size() == 2) { if(v[0] == "joker" || v[1] == "JOKER") flag = 6;//对王 else flag = 2;//普通顺子 } else if(v.size() == 3) flag = 3;//三个 else if(v.size() == 4) flag = 4;//** else if(v.size() == 5) flag = 5;//顺子 return flag; } //判断字符串是否合规 int myfind(vector<string> base,string v) { for(int i = 0;i<base.size();i++) { if(v == base[i]) return i; } return -1; } int main() { string str; while(getline(cin,str)) { int index = str.find("-"); string str1 = str.substr(0,index); string str2 = str.substr(index+1); vector<string> v1,v2; stringstream ss1(str1),ss2(str2); string tmp; while(ss1>>tmp) v1.push_back(tmp); while(ss2>>tmp) v2.push_back(tmp); int flag1 = judge(v1); int flag2 = judge(v2); vector<string> base={"3","4","5","6","7","8","9","10","J","Q","K","A","2","joker","JOKER"}; //判断**的情况 int win = 0; if(flag1==6||flag2==6 || flag1==4 || flag2==4) { if(flag1==6) win =1;//🈶️一个对王 else if (flag2==6) win =2; else if(flag1 == flag2 && flag1 == 4)//两边都是** { auto it1 = myfind(base,v1[0]);//返回对应base的索引 auto it2 = myfind(base,v2[0]); if(it1 != -1 && it2 != -1)//比较base的索引 { if(it1 > it2) win = 1; else win = 2; }else { win = 0; } } else if(flag1 == 4 && flag2 != 4) win = 1;//其中一边是** else if(flag1 != 4 && flag2 == 4) win = 2; } else if(flag1 == flag2) { auto it1 = myfind(base,v1[0]); auto it2 = myfind(base,v2[0]); if(it1 != -1 && it2 != -1) { if(it1 > it2) win = 1; else win = 2; }else { win = 0; } }else { win = 0; } if(win == 0) { cout<<"ERROR"<<endl; } else if(win == 1) { for(int i = 0;i<v1.size();i++) { cout<<v1[i]<<" "; } cout<<endl; } else if(win == 2) { for(int i = 0;i<v2.size();i++) { cout<<v2[i]<<" "; } cout<<endl; } } return 0; }
#include<iostream> #include<string> using namespace std; int CalSpc(string str) { int ans = 0; for (int i = 0; i < str.size(); i++) { if (str[i] == ' ') ans++; } return ans; } int CalChar(string str) { int ans = 0; for (int i = 0; i < str.size(); i++) { if (str[i] != ' ') ans++; } return ans; } int Findnum(string str) { int num; if (str == "10") num = 10; else if (str == "J") num = 11; else if (str == "Q") num = 12; else if (str == "K") num = 13; else if (str == "A") num = 14; else if (str == "2") num = 15; else if (str == "joker") num = 20; else if (str == "JOKER") num = 30; else num = str[0] - 48; return num; } class PokState { public: PokState(string s) :str(s) { } void CalPok() { int SpcNum = CalSpc(str); int CharNum = CalChar(str); if (SpcNum == 0) { PokType = 1; PokVal = Findnum(str); } else if (SpcNum == 1) { if (CharNum == 10) { PokType = 100; PokVal = 100; } else { PokType = 2; PokVal = Findnum(str.substr(0, str.find(' '))); } } else if (SpcNum == 2) { PokType = 3; PokVal = Findnum(str.substr(0, str.find(' '))); } else if (SpcNum == 3) { PokType = 10; PokVal = Findnum(str.substr(0, str.find(' '))); } else if (SpcNum == 4) { PokType = 5; PokVal = Findnum(str.substr(0, str.find(' '))); } else { PokType = -1; PokVal = -1; } } int PokType; int PokVal; string str; }; int main() { string s, LeftStr, RightStr; while (getline(cin, s)) { LeftStr = s.substr(0, s.find('-')); RightStr = s.substr(s.find('-') + 1, s.size() - 1); PokState LS(LeftStr); PokState RS(RightStr); LS.CalPok(); RS.CalPok(); if (LS.PokType == RS.PokType) //牌的类型相等,比较大小 { if (LS.PokVal > RS.PokVal) cout << LS.str << endl; else cout << RS.str << endl; } else if (LS.PokType == 100 || (LS.PokType > RS.PokType && LS.PokType == 10)) //王炸 或者 炸比对面大,直接输出 cout << LS.str << endl; else if (RS.PokType == 100 || (RS.PokType > LS.PokType && RS.PokType == 10)) //谁是王炸,直接输出 cout << RS.str << endl; else cout << "ERROR" << endl; } return 0; }
import java.util.*; public class Main { public static void main(String[] args) { /* 通过字符串长度(特征)将输入映射到牌型,但是10的长度为2,故转换为X */ Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String[] str = scanner.nextLine().split("-"); Map<String, String> map = new HashMap<String, String>(); Map<String, Integer> order = new HashMap<>(); { /*排序字典*/ order.put("3", 1); order.put("4", 2); order.put("5", 3); order.put("6", 4); order.put("7", 5); order.put("8", 6); order.put("9", 7); order.put("X", 8); order.put("J", 9); order.put("Q", 10); order.put("K", 11); order.put("A", 12); order.put("2", 13); } /*Mapping*/ for (int i=0;i<2;i++) { str[i]=str[i].replaceAll("10","X"); if (str[i].length() == 11) { map.put(str[i], "王炸"); } if (str[i].length() == 7) { map.put(str[i], "炸弹"); } if (str[i].length() == 9) { map.put(str[i], "顺子"); } if (str[i].length() == 1) { map.put(str[i], "单牌"); } if (str[i].length() == 3) { map.put(str[i], "对子"); } if (str[i].length() == 5) { map.put(str[i], "三个"); } } /*牌型相同*/ if (map.get(str[0]) == map.get(str[1])) { if(map.get(str[0]) == "王炸"){ System.out.println(str[0]); } else{ /*是否为单牌*/ if(str[0].length()>1){ String[] sample1 = str[0].split(" "); String[] sample2 = str[1].split(" "); System.out.println(order.get(sample1[0]) >=order.get(sample2[1])?str[0].replaceAll("X","10"):str[1].replaceAll("X","10")); }else { System.out.println(order.get(str[0])>=order.get(str[1])?str[0].replaceAll("X","10"):str[1].replaceAll("X","10")); } } /*牌型不同*/ } else if (map.get(str[0]) == "王炸" || map.get(str[1]) == "王炸") { System.out.println(map.get(str[0]) == "王炸" ? str[0] : str[1]); } else if (map.get(str[0]) == "炸弹" || map.get(str[1]) == "炸弹") { System.out.println(map.get(str[0]) == "炸弹" ? str[0] : str[1]); } else { System.out.println("ERROR"); } } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String s = sc.nextLine(); if(s.contains("joker JOKER")) { System.out.println("joker JOKER"); continue; } String s1 = s.split("-")[0]; s1 = s1.replaceAll("J", "11"); s1 = s1.replaceAll("Q", "12"); s1 = s1.replaceAll("K", "13"); s1 = s1.replaceAll("A", "14"); s1 = s1.replaceAll("2", "15"); String[] s1s = s1.split(" "); String s2 = s.split("-")[1]; s2 = s2.replaceAll("J", "11"); s2 = s2.replaceAll("Q", "12"); s2 = s2.replaceAll("K", "13"); s2 = s2.replaceAll("A", "14"); s1 = s1.replaceAll("2", "15"); String[] s2s = s2.split(" "); if(s1s.length==4 && s2s.length!=4) { System.out.println(s.split("-")[0]); } else if(s1s.length!=4 && s2s.length==4) { System.out.println(s.split("-")[1]); } else if(s1s.length==4 && s2s.length==4) { if(Integer.valueOf(s1s[0]) > Integer.valueOf(s2s[0])) { System.out.println(s.split("-")[0]); } else { System.out.println(s.split("-")[1]); } } else if(s1s.length==s2s.length) { if(Integer.valueOf(s1s[0]) > Integer.valueOf(s2s[0])) { System.out.println(s.split("-")[0]); } else { System.out.println(s.split("-")[1]); } } else { System.out.println("ERROR"); } } } }
#include <bits/stdc++.h> using namespace std; int DeleteSpace(string s) { int cnt = 1; for (int i = 0; i<s.size(); i++) { if (s[i] == ' ') cnt++; } return cnt; } vector<string> table = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER" }; int Value(string s) { int res; if (s[0] == '1') res = 10; else if (s[0] == '3') res = 3; else if (s[0] == '4') res = 4; else if (s[0] == '5') res = 5; else if (s[0] == '6') res = 6; else if (s[0] == '7') res = 7; else if (s[0] == '8') res = 8; else if (s[0] == '9') res = 9; else if (s[0] == 'J') res = 11; else if (s[0] == 'Q') res = 12; else if (s[0] == 'K') res = 13; else if (s[0] == 'A') res = 14; else if (s[0] == '2') res = 15; return res; } int main() { string str; while (getline(cin, str)) { string s1 = str.substr(0, str.find('-')); string s2 = str.substr(str.find('-') + 1); int n1 = DeleteSpace(s1); int n2 = DeleteSpace(s2); string Joker = "joker JOKER"; string Poker = "345678910JQKA2"; if (s1 == Joker) cout << s1 << endl; else if (s2 == Joker) cout << s2 << endl; else if (n1 == n2) { string f1, f2; f1 = s1.substr(0, s1.find(" ")); f1 = s2.substr(0, s2.find(" ")); int p1 = Value(s1); int p2 = Value(s2); //cout << p1 << endl; //cout << p2 << endl; //auto num1 = find(table.begin(), table.end(), f1); //auto num2 = find(table.begin(), table.end(), f2); if (p1>p2) cout << s1 << endl; else cout << s2 << endl; } else if (n1 == 4) cout << s1 << endl; else if (n2 == 4) cout << s2 << endl; else cout << "ERROR" << endl; } system("pause"); return 0; }
//由于题目保证合法输入,只需要根据长度判断就行,长度相等比较第一个数字,不等看是否有**; import java.util.HashMap; import java.util.Scanner; public class Main { private static void compar(String[] s, HashMap<String, Integer> map) { if (s[1].equals("joker JOKER")||s[0].equals("joker JOKER")) { System.out.println("joker JOKER"); return; } String res=""; String[] play1=s[0].split(" "); String[] play2=s[1].split(" "); int len1=play1.length,len2=play2.length; if (len1==len2) { res = map.get(play1[0]) > map.get(play2[0]) ?s[0]: s[1]; }else if (len1==4||len2==4) { res=len1==4?s[0]: s[1]; }else { res="ERROR"; } System.out.println(res); } public static void main(String[] args) { Scanner sc= new Scanner(System.in); TAG:while (sc.hasNext()) { String[] s=sc.nextLine().split("-"); HashMap<String, Integer> map=new HashMap<>(); map.put("3", 3); map.put("4", 4); map.put("5", 5); map.put("6", 6); map.put("7", 7); map.put("8", 8); map.put("9", 9); map.put("10", 10); map.put("J", 11); map.put("Q", 12); map.put("K", 13); map.put("A", 14); map.put("2", 16); map.put("joker", 17); map.put("JOKER", 18); compar(s,map); } sc.close(); } }
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int countCards(string s)//求一个串中字符(串)的个数,如1 2 joker返回3 { int res=0; for(unsigned i=0;i<s.size();) { while(s[i++]!=' '&&i<s.size()); res++; } return res; } int main() { string s; string helper="3456789tJQKA2oO";//t-10,o-joker,O-JOKER; while(getline(cin,s)) { size_t n=s.find('-'); string l=s.substr(0,n);string lcpy=l; string r=s.substr(n+1);string rcpy=r; for(unsigned i=0;i<l.size();i++) { if(l[i]=='j'&&l[i+1]=='o') l.replace(i,5,"o"); if(l[i]=='J'&&l[i+1]=='O') l.replace(i,5,"O"); if(l[i]=='1'&&l[i+1]=='0') l.replace(i,2,"t"); } for(unsigned i=0;i<r.size();i++) { if(r[i]=='j'&&r[i+1]=='o') r.replace(i,5,"o"); if(r[i]=='J'&&r[i+1]=='O') r.replace(i,5,"O"); if(r[i]=='1'&&r[i+1]=='0') r.replace(i,2,"t"); }//分别对l和r中的joker,JOKER和10替换 if((countCards(l)==1&&countCards(r)==1)||(countCards(l)==3&&countCards(r)==3)||(countCards(l)==4&&countCards(r)==4)||(countCards(l)==5&&countCards(r)==5)) { if(helper.find(l[0])>helper.find(r[0])) cout<<lcpy<<endl; else cout<<rcpy<<endl; } else if(countCards(l)==2&&countCards(r)==2) { if(l.find('o')==-1&&r.find('o')==-1) { if(helper.find(l[0])>helper.find(r[0])) cout<<lcpy<<endl; else cout<<rcpy<<endl; } else { if(l.find('o')==-1) cout<<rcpy<<endl; else cout<<lcpy<<endl; } } else if(countCards(l)==4&&countCards(r)!=4&&r.find('o')==-1) cout<<lcpy<<endl; else if(countCards(r)==4&&countCards(l)!=4&&l.find('o')==-1) cout<<rcpy<<endl; else if(countCards(l)==2&&l.find('o')!=-1) cout<<lcpy<<endl; else if(countCards(r)==2&&r.find('o')!=-1) cout<<rcpy<<endl; else cout<<"ERROR"<<endl; } }
while(line=readline()){ let porkers = line.split('-'); porker1 = porkers[0].split(' '); porker2 = porkers[1].split(' '); if (isTwoJoker(porkers[0])) { print(porkers[0]); } else if (isTwoJoker(porkers[1])) { print(porkers[1]); } else if (isBoom(porker1) && isBoom(porker2)) { print(porker2n(porker1[0]) > porker2n(porker2[0]) ? porkers[0] : porkers[1]); } else if (isBoom(porker1)) { print(porkers[0]); } else if (isBoom(porker2)) { print(porkers[1]); } else if (porker1.length !== porker2.length) { print('ERROR'); } else { for (let i = 0; i < porker1.length; i++) { porker1[i] = porker2n(porker1[i]); porker2[i] = porker2n(porker2[i]); } print(porker1[0] < porker2[0] ? porkers[1] : porkers[0]); } } function isBoom (porkers) { return porkers.length === 4 && new Set(porkers).size === 1; } function isTwoJoker (porker) { const twoJoker = ['joker JOKER', 'JOKER joker']; return twoJoker.includes(porker); } function porker2n (porker) { let n = parseInt(porker); const porkerMap = { 'J': 11, 'Q': 12, 'K': 13, 'A': 14, '2': 15 } if (n > 2) { return n; } else { return porkerMap[porker]; } }
#include<iostream>
#include<string>
using namespace std;
//***********对牌进行分类*****************
//1表示个,2表示对,3表示三个,4表示4个(**)
//5表示顺子,6表示对王(王炸)
int cardsClassify(const string& cards);
void cardsCompare(const string&, const string&);
int main(void)
{
string strTwoCards;
getline(cin, strTwoCards);
auto posMinus = strTwoCards.find('-');
string cardsOne = strTwoCards.substr(0, posMinus);//第二个参数表示len
string cardsTwo = strTwoCards.substr(posMinus + 1);
cardsCompare(cardsOne, cardsTwo);
return 0;
}
void cardsCompare(const string& cardsOne, const string& cardsTwo)
{
string standCardsSord("3 4 5 6 7 8 9 1 J Q K A 2");
int classifyOne = cardsClassify(cardsOne);
int classifyTwo = cardsClassify(cardsTwo);
if (classifyOne == 6) {
cout << cardsOne << endl;
return;
}
else if (classifyTwo == 6) {
cout << cardsTwo << endl;
return;
}
if (classifyOne == 4 && classifyTwo == 4) {
if (standCardsSord.find(cardsOne[0]) > standCardsSord.find(cardsTwo[0])) {
cout << cardsOne << endl;
return;
}
else {
cout << cardsTwo << endl;
return;
}
}
if (classifyOne == 4) {
cout << cardsOne << endl;
return;
}
if(classifyTwo == 4) {
cout << cardsTwo << endl;
return;
}
if (classifyOne != classifyTwo) {
cout << "ERROR" << endl;
return;
}
else {
if (standCardsSord.find(cardsOne[0]) > standCardsSord.find(cardsTwo[0])) {
cout << cardsOne << endl;
return;
}
else {
cout << cardsTwo << endl;
return;
}
}
}
int cardsClassify(const string& cards)
{
switch (cards.size()) {
case 1:
return 1;
case 2://特殊的10
return 1;
case 3:
return 2;
case 5://暂不考虑单张王joker
if (cards[0] == '1')//特殊的对10
return 2;
return 3;
case 8:
return 3;//特殊的10 10 10
case 7:
return 4;
case 9:
case 10://包含10的顺子
return 5;
case 11:
if (cards[0] == '1')//特殊的四个10**
return 4;
return 6;
default:
return 0;
}
}