Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this problem, we concentrate on Japanese Mahjong, a variation of mahjong. For brief, all of the word mahjong mentioned following refer to Japanese Mahjong.
Japanese mahjong is usually played with 136 tiles, which can be organized into several categories:
In this problem, we introduce two abnormal kinds of winning hand different from the normal winning hand, which consist of four melds and one eyes.
Now, given a hand with 14 tiles, can you answer this hand is which kind of abnormal kind of winning hand?
There are multiple cases. Each case consists of 28 characters in one line, describing 14 tiles. The manner for describing each type of tile is:
For each case, if the hand is Seven Pairs, output "Seven Pairs". If the hand is Thirteen Orphans, output "Thirteen Orphans". If the hand is neither Seven Pairs nor Thirteen Orphans, output "Neither!".
1z1z2z2z3z3z4z4z5z5z6z6z7z7z 1s9s1m9m1p9p1z2z3z4z5z6z7z7z 1s9s1m9m1p9p1z2z3z4z5z6z7z7p
Seven Pairs Thirteen Orphans Neither!
判断是七对还是十三幺,七对必须都不同
#include <stdio.h> #include <math.h> #include <string.h> #include <algorithm> using namespace std; int a[4][10],len; char str[50]; int main() { int i,j,flag; while(~scanf("%s",str)) { len = strlen(str); memset(a,0,sizeof(a)); for(i = 0; i<len; i+=2) { if(str[i+1] == ‘p‘) a[0][str[i]-‘0‘]++; else if(str[i+1] == ‘s‘) a[1][str[i]-‘0‘]++; else if(str[i+1] == ‘m‘) a[2][str[i]-‘0‘]++; else a[3][str[i]-‘0‘]++; } flag = 1; for(i = 0; i<4; i++) { for(j = 1; j<10; j++) { if(a[i][j] && a[i][j]!=2) { flag = 0; break; } } if(!flag) break; } if(flag) { printf("Seven Pairs\n"); continue; } if(a[0][1] && a[0][9] && a[1][1] && a[1][9] && a[2][1] && a[2][9] && a[3][1] && a[3][2] && a[3][3] && a[3][4] && a[3][5] && a[3][6] && a[3][7]) { if(a[0][1] == 2 || a[0][9] == 2 || a[1][1] == 2 || a[1][9] == 2 || a[2][1] == 2 || a[2][9] == 2 || a[3][1]==2 || a[3][2]==2 || a[3][3]==2 || a[3][4]==2 || a[3][5]==2 || a[3][6]==2 || a[3][7]==2) { printf("Thirteen Orphans\n"); continue; } } printf("Neither!\n"); } return 0; }
ZOJ3671:Japanese Mahjong III,布布扣,bubuko.com
原文地址:http://blog.csdn.net/libin56842/article/details/25651625