65,186
社区成员




#include <iostream>
using namespace std;
int count_letter(string str) {
int count;
for (int i=0; i<str.length(); ++i) {
bool flag = false;
for (int j=0; j<i; ++j) {
if (str[i]==str[j]) {
flag = true;
break;
} /*if*/
} /*for j*/
if (flag == false) {
count++;
} /*if*/
} /*for i*/
return count;
} /*letter()*/
int main() {
int round;
while (cin>>round, round!=-1) {
string ans, gus;
cin >> ans >> gus;
int letters = count_letter(ans);
int heals = 7;
char jl[50];
int jl_c = 0;
for (int i=0; i<gus.length(); ++i) {
int j; bool flag;
for (j=0, flag=false; j<jl_c; ++j) {
if (gus[i]==jl[j]) {
flag = true;
break;
} /*if*/
} /*for j*/
if (flag==true) {
continue;
} /*if*/
jl[jl_c++] = gus[i];
for (j=0, flag=false; j<ans.length(); ++j) {
if (gus[i]==ans[j]) {
flag = true;
break;
} /*if*/
} /*for j*/
if (flag==false) {
--heals;
if (heals==0) {
cout << "Round " << round << endl;
cout << "You lose." << endl;
break;
} /*if*/
} else {
--letters;
if (letters==0) {
cout << "Round " << round << endl;
cout << "You win." << endl;
break;
} /*if*/
} /*if-else*/
} /*for i*/
if (letters && heals) {
cout << "Round " << round << endl;
cout << "You chickened." << endl;
} /*if*/
} /*while*/
return 0;
} /*main()*/
#include <iostream>
#include <string>
using namespace std;
struct problem
{
int id;
long letters; // bit map of letters involved
int missed; // count of wrong guess
std::string input;
void check()
{
const char * msg[]={"win.","chickened out.","lose."};
cout<<"Round "<<id<<endl<<"You "<<msg[accept_guess(input)]<<endl;
}
void reset()
{
letters=missed=id=0;
}
// return 0 if win
// 1 if lose
// 2 if not yet done
int accept_guess(int bit)
{
//letter=1<<(letter-'a');
if(letters & bit )
letters &=~bit;
else
++missed;
return letters==0?0: missed>=7 ? 2 : 1;
}
// return 0 in case win
// 1 in case chickened out
// 2 in case lose
int accept_guess(const string& s)
{
int v;
int map=0;
for(unsigned i=0; i<s.length(); ++i)
{
int bit=1<<(s[i]-'a');
if(map&bit)
continue;
else
map|=bit;
if(1!=(v=accept_guess(bit)))
break;
}
return v;
}
};
std::istream& operator >>(std::istream& is, problem& p)
{
p.reset();
is>>p.id;
if(p.id!=-1)
{
do{
getline(is,p.input);
}while(is && p.input.empty());
for(unsigned i=0; i<p.input.length(); ++i)
{
long c=p.input[i]-'a';
c=1<<c;
p.letters |= c;
}
getline(is,p.input);
}
return is;
}
int main()
{
problem p;
while(cin>>p && p.id!=-1)
p.check();
return 0;
}