codeforces1191B Tokitsukaze and Mahjong 哈希+思维

网址:http://codeforces.com/contest/1191/problem/B

题意:

给出三张牌,问至少再需要几张牌才可以构成顺子或者扣子(顺子和扣子是什么见样例)

题解:

将字符串按照(数字$\times$$1$)+(字符$\times$$100$)生成数字,然后排序,如果是数字相等或者相邻的相减都是$1$,就输出$0$(一定是顺子或者扣子),如果只有一对相邻的相减是$0$(相同),$1$(数字相差$1$,字母不变),$2$(数字相差$2$,字母不变),就输出$1$,其他输出$2$。

AC代码:

    #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;
    	sort(a,a+3);
    	int t1=a[1]-a[0],t2=a[2]-a[1];
    	if(t1==t2&&(t1==1||t1==0))//shunzi
    		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;
    }

 

posted @ 2019-07-14 00:54  Aya_Uchida  阅读(196)  评论(0编辑  收藏  举报