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 11 to 99). 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:
Some examples:
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 11 to 99 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
Copy
1s 2s 3s
output
Copy
0
input
Copy
9m 9m 9m
output
Copy
0
input
Copy
3p 9m 2p
output
Copy
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].
一道模拟题
#include<bits/stdc++.h>
using namespace std;
struct node{
int a;
char b;
} t[4];
bool cmp(node a, node b){
if(a.b == b.b) return b.a > a.a;
return b.b > a.b;
}
int main(){
for(int i = 0; i < 3; i++){
cin >> t[i].a >> t[i].b;
}
sort(t, t + 3, cmp);
/*for(int i = 0; i < 3; i++){
cout << t[i].a << t[i].b;
}*/
if( t[0].b == t[1].b && t[0].b == t[2].b && t[1].b == t[2].b ){
if(t[0].a - t[1].a == -1 && t[1].a - t[2].a == -1 || (t[0].a == t[1].a && t[0].a == t[2].a && t[1].a == t[2].a))
cout << "0" << endl;
else{
if(t[0].a - t[1].a == -2 || t[1].a - t[2].a == -2 || t[0].a - t[1].a == -1 || t[1].a - t[2].a == -1 || t[0].a - t[1].a == 0 || t[1].a - t[2].a == 0)
cout << "1" << endl;
else
cout << "2" << endl;
}
}
else{
if(t[0].b != t[1].b && t[0].b != t[2].b && t[1].b != t[2].b){
cout << "2" << endl;
}
if(t[0].b == t[1].b){
if(t[0].a == t[1].a)
cout << "1" << endl;
if(t[0].a - t[1].a == -1 || t[0].a - t[1].a == -2)
cout << "1" << endl;
if(t[0].a - t[1].a < -2)
cout << "2" << endl;
}
if(t[0].b == t[2].b){
if(t[0].a == t[2].a)
cout << "1" << endl;
if(t[0].a - t[2].a == -1 || t[0].a - t[2].a == -2)
cout << "1" << endl;
if(t[0].a - t[2].a < -2)
cout << "2" << endl;
}
if(t[1].b == t[2].b){
if(t[1].a == t[2].a)
cout << "1" << endl;
if(t[1].a - t[2].a == -1 || t[1].a - t[2].a == -2)
cout << "1" << endl;
if(t[1].a - t[2].a < -2)
cout << "2" << endl;
}
}
}