标签:
输入两手牌,两手牌之间用“-”连接,每手牌的每张牌以空格分隔,“-”两边没有空格,如4 4 4 4-joker JOKER。
输出两手牌中较大的那手,不含连接符,扑克牌顺序不变,仍以空格隔开;如果不存在比较关系则输出ERROR。
4 4 4 4-joker JOKER
joker JOKER
1 // 0712.cpp : Defines the entry point for the console application. 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <vector> 7 #include <string> 8 9 using namespace std; 10 11 string str1,str2; 12 13 int gettype(string str) 14 { 15 int type;//dan 1 dui 2 san 3 shun 4 zha 5 duiwang 6 16 if(str.length()==11 && str[0]==‘j‘) 17 type = 6; 18 else if(str.length() == 9 || str.length() == 10) 19 type = 4; 20 else if(str.length() == 7 || (str.length() == 11 && str[0]==‘1‘ && str[1]==‘0‘)) 21 type = 5; 22 else if((str.length() == 5 && str[1]==‘ ‘) || str.length() == 8) 23 type = 3; 24 else if(str.length() == 3 || (str.length() == 5 && str[0]==‘1‘ && str[1]==‘0‘)) 25 type = 2; 26 else if(str.length() == 1 || str.length() == 2) 27 type = 1; 28 return type; 29 } 30 void compare(int t1,int t2) 31 { 32 if(t1 != t2) 33 { 34 if(t1 == 6) 35 { 36 cout<<str1<<endl; 37 return; 38 } 39 else if(t2 == 6) 40 { 41 cout<<str2<<endl; 42 return; 43 } 44 else if(t1 == 5) 45 { 46 cout<<str1<<endl; 47 return; 48 } 49 else if(t2 == 5) 50 { 51 cout<<str2<<endl; 52 return; 53 } 54 else 55 { 56 cout<<"ERROR"<<endl; 57 return; 58 } 59 } 60 else 61 { 62 if(str1[1]==‘0‘) 63 { 64 if(str2[0]>=‘3‘ && str2[0]<=‘9‘) 65 { 66 cout<<str1<<endl; 67 return; 68 } 69 else 70 { 71 cout<<str2<<endl; 72 return; 73 } 74 } 75 else if(str2[1]==‘0‘) 76 { 77 if(str1[0]>=‘3‘ && str1[0]<=‘9‘) 78 { 79 cout<<str2<<endl; 80 return; 81 } 82 else 83 { 84 cout<<str1<<endl; 85 return; 86 } 87 } 88 else if(str1[1]==‘ ‘ && str2[1]==‘ ‘) 89 { 90 if(str1[0]==‘2‘) 91 { 92 cout<<str1<<endl; 93 return; 94 } 95 else if(str2[0]==‘2‘) 96 { 97 cout<<str2<<endl; 98 return; 99 } 100 else if(str1[0]==‘A‘) 101 { 102 cout<<str1<<endl; 103 return; 104 } 105 else if(str2[0]==‘A‘) 106 { 107 cout<<str2<<endl; 108 return; 109 } 110 else if(str1[0]>=‘3‘ && str1[0]<=‘K‘ && str2[0]>=‘3‘ && str2[0]<=‘K‘) 111 { 112 if(str1>str2) 113 { 114 cout<<str1<<endl; 115 return; 116 } 117 else 118 { 119 cout<<str2<<endl; 120 return; 121 } 122 } 123 124 } 125 126 127 128 } 129 130 } 131 132 int main(void) 133 { 134 135 int type1,type2; 136 137 while(getline(cin,str1,‘_‘)) 138 { 139 140 getline(cin,str2); 141 type1 = gettype(str1); 142 type2 = gettype(str2); 143 144 compare(type1,type2); 145 } 146 return 0; 147 }
标签:
原文地址:http://www.cnblogs.com/hhboboy/p/5665323.html