题目链接:点击打开链接
题目大意及思路等参照紫书79-81页,也有代码。
AC代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int n, lena, lens, lefta;
int win, lose, chance;
char a[105], s[105];
void guess(char ch)
{
int bad = 1;
for(int i = 0; i < lena; ++i)
if(a[i] == ch) { lefta--; a[i] = ' '; bad = 0;}
if(bad) chance--;
if(!chance) lose = 1;
if(!lefta) win = 1;
//cout << bad << " " << chance << " " << lefta << endl;
}
int main()
{
while(~scanf("%d",&n) && n != -1)
{
win = lose = 0;
chance = 7;
scanf("%s %s",a, s);
lena = lefta = strlen(a);
lens = strlen(s);
for(int i = 0; i < lens; ++i)
{
guess(s[i]);
if(win || lose) break;
}
cout << "Round " << n << endl;
if(win) cout << "You win." << endl;
else if(lose) cout << "You lose." << endl;
else cout << "You chickened out." << endl;
}
return 0;
}