这是第四章的做的第一个题,说来惭愧,到现在才做了这么点题,要加把劲了!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int m,n,i,j,k,r,s,t,round,la,lb,lan,x,score;
char a[1000],b[1000],answer[100];
while(scanf("%d",&round) != EOF)
{
if(round == -1)
break;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(answer,0,sizeof(answer));
s=0; x=1;
getchar();
gets(a); la=strlen(a);
gets(b); lb=strlen(b);
for(i=0; i<la; i++)
for(j=i+1; j<la; j++)
if(a[i] == a[j])
a[j]=x++;
t=0;
for(i=0; i<la; i++)
if(a[i] >=97 && a[i] <= 122)
answer[t++]=a[i];
lan=strlen(answer);
for(i=0; i<lb; i++)
for(j=i+1; j<lb; j++)
if(b[i] == b[j])
b[j]=x++;
printf("Round %d\n",round);
score=0; s=0;
for(i=0; i<lb; i++)
{
r=0;
for(j=0; j<lan; j++)
if( b[i] == answer[j])
r=1;
if(r==1)
score++;
else
s++;
if(score == lan && s<=6)
{
printf("You win.\n");
goto loop;
}
}
if(score < lan && s<=6)
printf("You chickened out.\n");
else if(s>6)
printf("You lose.\n");
loop: continue;
}
return 0;
}