K - SSY and JLBD

K - SSY and JLBD
Mahjong is a board game with a long history. But Mahjong has different rules in different city.

A deck of mahjong consists of 136 cards. It contains 1-9 card in three suits,and Seven kinds of word card(“dong”,“nan”,“xi”,“bei”,“zhong”,“fa”,“bai”),there are 4 same cards for each kind of card in a deck of mahjong .

In a mysterious country, the rules of mahjong are very simple.In the game,each Player has 14 cards.There are only two ways people can win the game:

  1. shisanyao:You should have all 1 and 9 card in three suits and seven kinds of word card at the same time,and an extra card with any kind of 1 and 9 or word.

  2. jiulianbaodeng:Firstly,You should make sure that you have the same suit in your hand.Secondly, for card “1” and card “9”,you should have at least three . but for card “2” to card “8”,at least one.For example, both “11112345678999” and “11122345678999” can win the game.

Now you know a player’s 14 cards. Please judge which card type he can use to win the game.
Input

The input file contains 14 lines.Each line has a string representing a card.

For three suits of card “1” to card “9”,We use two characters for the type,the first character a is number 1 to 9,and the second character b represents the suit.(a∈{1,2,3,4,5,6,7,8,9},b∈{s,p,w})

For the word cards,as shown in the description,we use full spelling pinyin represent them.
Output

If player ‘s card meet the “shisanyao” condition, you should output “shisanyao!”.

If player ‘s card meet the “jiulianbaodeng” condition, you should output “jiulianbaodeng!”.

Otherwise,you should output “I dont know!”.

Sample Input

1w
5w
2w
6w
5w
9w
9w
7w
1w
3w
9w
4w
1w
8w

Sample Output

jiulianbaodeng!

解题思路:

  • 用3个数组分别记录w、s、p类型牌从1~ 9的个数,再用一个数组zi记录字类型的个数,再再用一个数组记录2~8的个数。
  • 当2~8的个数都大于1时(表示2–8都存在),并且同一套牌 1的个数大于3个并且同一套牌 9的个数大于3个时,输出jiulianbaodeng!
  • 当所以字牌都存在且存在1和9 ,最后一张是1 或9或字牌时输出shisanyao!
#include<stdio.h>
#include<string.h>
int main()
{
	char name[14];
	int w[10]={0},s[10]={0},p[10]={0},z[10]={0};
	int zi[7]={0};
	for(int i=0;i<14;i++)
	{
		scanf("%s",name);
		getchar();
		if(name[1]=='w')
		{
			w[name[0]-'0']++;
			z[name[0]-'0']++;
		}
		else if(name[1]=='s')
		{
			s[name[0]-'0']++;
			z[name[0]-'0']++;
		}else if(name[1]=='p')
		{
			p[name[0]-'0']++;
			z[name[0]-'0']++;
		}else if(strcmp(name,"dong")==0){
		zi[0]++;}
		else if(strcmp(name,"nan")==0){
		zi[1]++;}
		else if(strcmp(name,"xi")==0){
		zi[2]++;}
		else if(strcmp(name,"bei")==0){
		zi[3]++;}
		else if(strcmp(name,"zhong")==0){
		zi[4]++;}
		else if(strcmp(name,"fa")==0){
		zi[5]++;}
		else if(strcmp(name,"bai")==0){
		zi[6]++;}
	}
	int flag=1;
	for(int i=2;i<=8;i++)
	{
		if(z[i]<=0)
		flag=0; //全有flag=1; 
	}
	int flag1=1,flag2=0;
	for(int i=0;i<7;i++)
	{
		if(zi[i]<=0)
		flag1=0;
		if(zi[i]>1)
		flag2=1;
	} 
	//同一套牌 1的个数大于3并且 同一套牌 9的个数大于3并且2~8的牌都有时 
	if((w[1]>=3&&w[9]>=3&&flag==1)||(s[1]>=3&&s[9]>=3&&flag==1)||(p[1]>=3&&p[9]>=3&&flag==1)){ 
		printf("jiulianbaodeng!\n");
	}//所以字牌都存在并且存在1和9 
	else if(w[1]>0&&s[1]>0&&p[1]>0&&w[9]>0&&s[9]>0&&p[9]>0&&flag1==1){  
		if(z[1]>1||z[9]>1||flag2==1)//最后一张牌是1和9或字时 
		{
			printf("shisanyao!\n");
		}else
		printf("I dont know!\n");
	}else{
	printf("I dont know!");}
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

giao源

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

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

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

打赏作者

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

抵扣说明:

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

余额充值