细节上我和人家没得比
毕竟咱取了巧没看原题,只凑合了个大概
但是我感觉思想上还是代某先进那么一点点
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 100;
int win;
int lef;//left保留字不要用 目标词还有几个没有被够着
int lose;
int chance;//还有几次猜错的机会
char s[maxn] = {0};
char s2[maxn] = {0};
void guess(char ch)//s2从头到尾来这走一遭
{
int bad = 1;//默认不中
for(int i = 0; i < strlen(s); i++)
{
if(s[i] == ch)
{
lef--;//哎 没有捞出来的又少了一个
s[i] = ' ';
bad = 0;//不好意思 百步穿杨
}//没有立即break的原因是这种字母可能重复出现
}
if(bad)//如果猜不中
{
chance--;
}
if(!chance)//机会没了
{
lose = 1;
}
if(!lef)//全捞出来了
{
win = 1;
}
}
int main()
{
int rnd;//本意round第几轮的意思因为保留字而用缩略
while(scanf("%d%s%s",&rnd,s,s2) == 3 && rnd != -1)
{
printf("Round %d\n",rnd);
win = lose = 0;
lef = strlen(s);
chance = 7;
for(int i = 0; i < strlen(s2); i++)
{
guess(s2[i]);
if(win || lose)
{
break;
}
}
if(win)
{
printf("You win.\n");
}
else if(lose)
{
printf("You lose.\n");
}
else
{
printf("You chickened out.\n");
}
}
return 0;
}


京公网安备 11010502036488号