ZOJ3671:Japanese Mahjong III

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:

  • Suited tiles. All suited tiles are of a rank and a suit.There are three suits of tiles, with ranks ranging from one to nine. There are four tiles of each rank and suit combination, thus there are 36 tiles in a suit, and 108 suited tiles in total.

    • The circle suit

    • The bamboo suit

    • The character suit

  • Honor tiles. Honor Tiles are tiles that do not have a rank or suit. They are divided into two categories. There are four types of Wind tiles and three types of Dragon tiles, with four of each type of honor tile. Thus, there are 16 wind tiles and
    12 Dragon tiles for 28 honor tiles.

    • Wind tiles. The Wind tiles consist of four kinds of tile: EastSouthWest, and North.

    • Dragon tiles. The Dragon titles consist of three types of tile: RedGreenWhite.

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.

  1. Seven Pairs: the hand consists of seven different pairs. No two pairs are the same. For example:
  2. Thirteen Orphans: the hand consists of thirteen kinds of tiles: Circle One, Circle Nine, Bamboo One, Bamboo Nine, Character One, Character Nine, East, South, West, North, Red, Green and White. Only
    one kind of them are two tiles, while the others are all only one tile. For example: 

Now, given a hand with 14 tiles, can you answer this hand is which kind of abnormal kind of winning hand?

Input

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:

  • Two characters stand for one tile.
  • For Suited tiles, the first is a integer ranged from one to nine, the tile‘s rank, and the second is a character: ‘p‘ for the circle suit, ‘s‘ for
    the bamboo suit, and ‘m‘ for the character suit.
  • For Honor tiles, the first is a integer: from one to seven stands for EastSouthWestNorthWhiteGreen,
    and Red respectively. The second one is always ‘z‘.

We promise that the input is a legal hand, which means there isn‘t another type of tiles described above or there are more than four same tiles.

Output

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!".

Sample Input

1z1z2z2z3z3z4z4z5z5z6z6z7z7z
1s9s1m9m1p9p1z2z3z4z5z6z7z7z
1s9s1m9m1p9p1z2z3z4z5z6z7z7p

Sample Output

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

时间: 2024-08-01 22:43:05

ZOJ3671:Japanese Mahjong III的相关文章

ZOJ 3671 Japanese Mahjong III

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3671 Japanese Mahjong III Time Limit: 2 Seconds      Memory Limit: 65536 KB Mahjong is a game of skill, strategy and calculation and involves a certain degree of chance. In this proble

ZOJ3669:Japanese Mahjong I

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 Mahjon

lintcode 主元素:majority number III主元素III

题目 主元素 III 给定一个整型数组,找到主元素,它在数组中的出现次数严格大于数组元素个数的1/k. 样例 给出数组 [3,1,2,3,2,3,3,4,4,4] ,和 k = 3,返回 3 注意 数组中只有唯一的主元素 挑战 要求时间复杂度为O(n),空间复杂度为O(k) 解题 上一题刚介绍过所用的方法,但是这个确实很复杂的 先利用HashMap实现 public class Solution { /** * @param nums: A list of integers * @param k

lintcode 中等题:Single number III 落单的数III

题目 落单的数 III 给出2*n + 2个的数字,除其中两个数字之外其他每个数字均出现两次,找到这两个数字. 样例 给出 [1,2,2,3,4,4,5,3],返回 1和5 挑战 O(n)时间复杂度,O(1)的额外空间复杂度 解题 根据落单的数I,可以想到,所有的数进行异或运行的结果就是所求两个数的异或结果. 这个异或的结果,二进制数是1的位置说明这两个数对应的二进制位不相同.然后再怎么还原???参考,理解的不是很透,找到第k位后,再判断数组中所以数的第k位是0 还是1,,出现两次的数对求解无影

Leetcode题目:House Robber III

题目: The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all

leetcode笔记:Contains Duplicate III

一. 题目描述 Given an array of integers, find out whether there are two distinct indices i and j in the array such that the difference between nums[i] and nums[j] is at most t and the difference between i and j is at most k. 二. 题目分析 题目大意是,给定一个整数数组,判断其中是否存

leetcode笔记:House Robber III

一. 题目描述 The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "

zoj 3669 Japanese Mahjong I

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3669 题目大意:就是给你一副牌,问你胡牌的方式有几种,并输出方式..... 思路:因为一副牌的数量不多,所以可以直接枚举每一张牌,判断加上这张牌后能否胡牌... code: #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #incl

leetcode笔记:Combination Sum III

一. 题目描述 Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Ensure that numbers within the set are sorted in ascending order. E