B. Tokitsukaze and Mahjong

time limit per test1 second

memory limit per test256 megabytes

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

outputCopy

0

inputCopy

3p 9m 2p

outputCopy

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

题解

答案就3种,0,1,2;0张直接check,1就加一张check,2就剩下的。

代码

#include<bits/stdc++.h>
using namespace std; pair<int,int> form(string s){
pair<int,int> p;
p.first=int(s[0]-'0');
if(s[1]=='m'){
p.second=0;
}else if(s[1]=='p'){
p.second=1;
}else{
p.second=2;
}
return p;
}
bool check(vector<pair<int,int> >v){
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++){
for(int j=i+1;j<v.size();j++){
for(int k=j+1;k<v.size();k++){
if(v[i].second==v[j].second&&v[j].second==v[k].second){
if(v[i].first==v[j].first&&v[j].first==v[k].first){
return true;
}
if(v[i].first+1==v[j].first&&v[j].first+1==v[k].first){
return true;
}
}
}
}
}
return false;
}
int main(){
vector<pair<int,int> >v;
for(int i=0;i<3;i++){
string s;
cin>>s;
v.push_back(form(s));
}
if(check(v)){
cout<<"0"<<endl;
return 0;
}
for(int i=1;i<10;i++){
for(int j=0;j<3;j++){
vector<pair<int,int> >d = v;
d.push_back(make_pair(i,j));
if(check(d)){
cout<<"1"<<endl;
return 0;
}
}
}
cout<<"2"<<endl;
return 0;
}

Codeforces Round #573 (Div. 2) Tokitsukaze and Mahjong 水题的更多相关文章

  1. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  2. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  3. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  4. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  5. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  6. Codeforces Round #335 (Div. 2) B. Testing Robots 水题

    B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...

  7. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  8. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  9. Codeforces Round #188 (Div. 2) A. Even Odds 水题

    A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...

随机推荐

  1. Google工作法

    本文转自:https://www.yuque.com/heqingbao/msfy2c/zg56gm 这几天去上海参加Google开发者大会,利用空闲时间读了一本快餐书,书名叫<Google工作 ...

  2. IT兄弟连 HTML5教程 HTML5技术的应用现状及HTML5平台的兴起

    HTML5的优良特性很快被各种类型的网站利用,比如文件拖拽到网页上传功能,多数即使用HTML5提供的新属性就可以完成,来实现素材的免插件拖放.因此,HTML5技术实际上在国内已经获得了较广泛的应用与支 ...

  3. 在windows实现nginx滚动日志

    nginx自身并不能够切分或滚动日志,因此只能用一个bat脚本按天切割日志,并删除三天前的日志 @echo off rem nginx滚动日志 rem nginx工作目录 set workspace= ...

  4. SQL Server内部如何管理对象的数据Page?

    一个表或Index使用的数据页空间是由IAM Page Chain来管理的.SQL Server 使用一个IAM(Index Allocation Map)Page来管理数据库文件中最多4GB的空间, ...

  5. Python中最常用的字符串方法!

    字符串是字符序列.Python中内置的string类代表基于Unicode国际字符集的字符串.除了Python中常见的操作外,字符串还有一些专属于它们的附加方法.下图显示了所有这些可用的方法: Pyt ...

  6. Android studio down 的项目中文出现 乱码

    发现down的项目file->open找到文件夹打开,里面少很多东西,像build.grade(好像拼错了). 这个问题是要file->import progect找到文件夹打开,as会自 ...

  7. MySQL数据库的事务及存储引擎

    一.关系型数据库与非关系型数据库 1.关系型数据库的特点: 1)数据以表格的形式出现 2)每行为各种记录名称 3)每列为记录名称所对应的数据域 4)许多的行和列组成一张表单 5)若干的表单组成数据库 ...

  8. 易优CMS:【小白学标签】之empty的基础用法

    [基础用法] 名称:empty 功能:判断某个变量是否为空,可以嵌套到任何标签里面使用,比如:channel.type等 语法: {eyou:empty name='$eyou.field.seo_t ...

  9. git 多账户链接不同gitlab仓库

    1.若之前对 git 设置过全局的 user.name 和 user.email.类似(用git config --global --list 进行查看你是否设置) 一定要清除之前设置的用户和邮箱 $ ...

  10. React教程:4 个 useState Hook 示例

    摘要: React示例教程. 原文:快速了解 React Hooks 原理 译者:前端小智 到 React 16.8 目前为止,如果编写函数组件,然后遇到需要添加状态的情况,咱们就必须将组件转换为类组 ...