欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVa489刽子手

程序员文章站 2024-03-19 08:42:22
...
#include<stdio.h>
#include<string.h>
#define maxn 100
char s1[maxn],s2[maxn];

int Guess();

int main(){
	int i,T=1;
	while(scanf("%d",&T) == 1){
		if(T == -1)
			break;
		scanf("%s",s1);
		scanf("%s",s2);
		i=Guess();
		printf("Round %d\n",T);
		if(i == 1)
			printf("You win.\n");
		else if(i == 0)
			printf("You lose.\n");
		else
			printf("You chickened out.\n");
	}
	return 0;
}

int Guess(){
	int i,j=0,len1,tag,len2,chance=7,left;
	len1=strlen(s1);
	len2=strlen(s2);
	left = len1;
	while(chance && j<len2){
		tag = 0;
		for(i=0;i<len1;i++){
			if(s2[j] == s1[i]){
				s1[i]=' ';
				tag = 1;
				left--;
			}
		}
		if(left == 0)
			return 1;
		if(tag == 0)
			chance--;
		j++;
	}
	if(chance != 0)
		return -1;
	else
		return 0;
}