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;
}

最新文章

  1. dotnet获取PDF文件的页数
  2. lower_bound()函数
  3. Hadoop 2.6.0编译on mac
  4. asp.net使用post方式action到另一个页面,在另一个页面接受form表单的值!(报错,已解决!)
  5. 安装阿里云的php+mysql+nginx+vsftpd
  6. JavaWeb之HTTP协议
  7. Caffe的运行mnist手写数字识别
  8. [NOIp 2017]列队
  9. Xpath语法详解
  10. 15_Raid及mdadm命令 _LVM
  11. Keepalived详解(四):通过vrrp_script实现对集群资源的监控【转】
  12. ssh服务器配置
  13. 一个servlet处理多个请求或者叫方法
  14. JavaScript笔记 #07# 用js写算法
  15. 【UOJ#22】【UR#1】外星人
  16. Ubuntu14.04下安装Libsvm,并使用Libsvm
  17. Python网络通信
  18. OpenGL11-绘制汉字最高效方法(使用Freetype)(代码已更新)
  19. MyBatis入门(一)—— 入门案例
  20. 【数据结构系列】线段树(Segment Tree)

热门文章

  1. NLP中的数据增强
  2. 趣谈Linux操作系统学习笔记:第二十四讲
  3. SpringBoot系列之快速创建项目教程
  4. Jenkins—Master/Slave模式
  5. Java-100天知识进阶-Java内存-知识铺(四)
  6. javaAPI操作Hbase
  7. Mac 应用程序不能打开解决方法
  8. oracle学习笔记(十七) PL/SQL高级应用
  9. MySQL EXPLAIN 语句
  10. .net post请求wcf