/*
入门经典P80-81有题解,十分详细
入门经典上有提醒,猜一个已经猜过的字母也算错...我英语理解能力不是太好,猜测应该是原题里的这句话"Each unique wrong guess only counts against the contestant once.",也许是表示每次错误的猜测都是单独起作用的?所以如果两次猜错都是同一个字母,那就错两次?
总而言之,英文阅读能力还是要加强,不然连题目都读不懂 T^T
另外发现,我用C++写的时候,DevC上居然报了一堆编译错,说left变量有问题,后来想了想,left应该算C++的关键字,因为IO流控制输入输出时,是有ios::left表示输入时左对齐的,所以就换成了rest
务必谨慎!~就像之前遇到过的,round和clock也是C++有的函数,不要再用它们定义变量名了...越学越发现直接基础并不太扎实,加油加油,日进有功!
*/
#include <iostream>
#include <cstring>
//#define debug
using namespace std;
const int maxn = 1005;
int rest, chance, win, lose;
char word[maxn], ans[maxn];
void guess(char ch)
{
bool flag = false;
int len = strlen(word);
for (int i = 0; i < len; i++)
if (word[i] == ch)
{
rest--; word[i] = ' '; flag = true;
}
if (!flag) chance--;
if (!chance) lose = 1;
if (!rest) win = 1;
}
int main()
{
#ifdef debug
freopen("E:\\in.txt", "r", stdin);
freopen("E:\\out.txt", "w", stdout);
#endif
int rnd;
while (cin >> rnd >> word >> ans && rnd != -1)
{
win = lose = 0;
chance = 7;
rest = strlen(word);
int len = strlen(ans);
for (int i = 0; i < len; i++)
{
guess(ans[i]); //猜一个字母
if (win || lose) break; //检查状态
}
//根据结果进行输出
cout << "Round " << rnd << endl;
if (win) cout << "You win.";
else if (lose) cout << "You lose.";
else cout << "You chickened out.";
cout << endl;
}
#ifdef debug
fclose(stdin);
fclose(stdout);
#endif
return 0;
}