B. Tokitsukaze and Mahjong

传送门

B. Tokitsukaze and Mahjong

time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output

Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1
to 9). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, …, 9m, 1p, 2p, …, 9p, 1s, 2s, …, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?Here are some useful definitions in this game:
A mentsu, also known as meld, is formed by a koutsu or a shuntsu;
A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples: [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu; [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.

Input
The only line contains three strings — the tiles in Tokitsukaze’s hand. For each string, the first character is a digit ranged from 1 to 9 and the second character is m, p or s.

Output
Print a single integer — the minimum number of extra suited tiles she needs to draw.

Examples
Input
1s 2s 3s
Output
0

Input
9m 9m 9m
Output
0

Input
3p 9m 2p
Output
1

Note
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].

题意:手上有三张牌,问至少另外需要几张牌可以构成shuntsu或者koutsu.。一共三种情况。第一种当字母相同且数字相同或者数字均增加1则输出0.第二种当字母两个相同且数字两个相同或则数字均增加1或者2,则输入1。其他情况输出2.

思路:输入是数字+字母形式,所以可以将字母转换为数字的形式。后排序进行相减进行上述条件的判断

代码

#include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	string str;
    	int a[3];
    	for(int i=0;i<3;++i)
    		cin>>str,a[i]=(str[0]-'0')+(str[1]-'a')*100;//strp[0]为数字,str[1]为字母,为了区别开将字母转换后*100
    	sort(a,a+3);//排序
    	int t1=a[1]-a[0],t2=a[2]-a[1];//相邻相减
    	if(t1==t2&&(t1==1||t1==1))//第一种情况
    		cout<<0<<endl;
    	else if(t1==0||t1==1||t1==2||t2==0||t2==1||t2==2)//第二种情况
    		cout<<1<<endl;
    	else//第三种情况
    		cout<<2<<endl;
    	return 0;
    }




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值