模拟 hihoCoder 1177 顺子

 

题目传送门

 1 /*  2  模拟:简单的照着规则做就可以了,把各种情况考虑到,虽然比赛写的丑了点,但能1Y还是很开心的:)  3 */  4 #include <cstdio>  5 #include <cstring>  6 #include <iostream>  7 #include <algorithm>  8 #include <cmath>  9 using namespace std; 10 11 const int MAXN = 1e2 + 10; 12 const int INF = 0x3f3f3f3f; 13 struct Card 14 { 15 int v, w; 16 }ca[10]; 17 char s[10][10]; 18 19 bool cmp(Card x, Card y) {return x.v < y.v;} 20 21 int main(void) //hihoCoder 1177 顺子 22 { 23 while (scanf ("%s %s %s %s", s[1], s[2], s[3], s[4]) == 4) 24  { 25 int pre = 0; bool ok = true; 26 for (int i=1; i<=4; ++i) 27  { 28 int len = strlen (s[i]); 29 if (s[i][0] == 'A') ca[i].v = 14; 30 else if (s[i][0] == 'J') ca[i].v = 11; 31 else if (s[i][0] == 'Q') ca[i].v = 12; 32 else if (s[i][0] == 'K') ca[i].v = 13; 33 else 34  { 35 if (len == 3) ca[i].v = 10; 36 else ca[i].v = s[i][0] - '0'; 37  } 38 int p = 1; if (len == 3) p = 2; 39 if (s[i][p] == 'S') ca[i].w = 1; 40 else if (s[i][p] == 'H') ca[i].w = 2; 41 else if (s[i][p] == 'C') ca[i].w = 3; 42 else if (s[i][p] == 'D') ca[i].w = 4; 43 if (i == 1) pre = ca[1].w; 44 else 45  { 46 if (ca[i].w != pre) ok = false; //是否四张牌都相同花色 47  } 48  } 49 50 sort (ca+1, ca+1+4, cmp); 51 int flag = 0; bool no = false; 52 for (int i=2; i<=4; ++i) 53  { 54 if (ca[i].v - ca[i-1].v == 1) continue; 55 else if (ca[i].v - ca[i-1].v == 2) 56  { 57 if (!flag) flag = i; 58 else no = true; 59  } 60 else no = true; 61  } 62 63 if (no) puts ("0/1"); //若有来两个地方不是连续的则不可能是顺子 64 else 65  { 66 if (flag) //如果在中间插入牌 67  { 68 if (ok) {puts ("1/16");} 69 else {puts ("1/12");} 70  } 71 else //两侧插牌 72  { 73 if (ok) 74  { 75 if (ca[1].v == 2 || ca[4].v == 14) puts ("1/16"); 76 else puts ("1/8"); 77  } 78 else 79  { 80 if (ca[1].v == 2 || ca[4].v == 14) puts ("1/12"); 81 else puts ("1/6"); 82  } 83  } 84  } 85  } 86 87 return 0; 88 }

 

你可能感兴趣的:(code)