猜完了要跳出来= =wa了好多发
#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<time.h>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
using namespace std;
const int INF = 0x3f3f3f3f;
void guess(char * str1, char * str2)
{
int len1 = strlen(str1);
int len2 = strlen(str2);
int sum = 0;
int left = len1;
for (int i = 0;i<len2;i++)
{
int bad = 1;
char temp = str2[i];
for (int j = 0;j<len1;j++)
{
if (temp == str1[j])
{
left--;
str1[j] = ' ';
bad = 0;
}
}
if (bad)
sum++;
if (sum == 7||!left)
break;
}
if (sum < 7 && !left)
cout << "You win." << endl;
else if (sum ==7)
cout << "You lose." << endl;
else
cout << "You chickened out." << endl;
}
int main()
{
int n;
while (cin >> n)
{
char str1[500], str2[500];
if (n == -1)
return 0;
cout << "Round " << n << endl;
cin >> str1;
cin >> str2;
guess(str1, str2);
}
return 0;
}
刘汝佳大神的
#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include<time.h>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
using namespace std;
const int INF = 0x3f3f3f3f;
int lf, chance;
int win, lose;
void guess(char * str1, char * str2)
{
lf = strlen(str1);
win = lose = 0;
chance = 7;
int len1 = strlen(str1);
int len2 = strlen(str2);
for (int i = 0;i <len2;i++)
{
char ch = str2[i];
int bad = 1;
for (int j = 0;j < len1;j++)
{
if (str1[j] == ch)
{
lf--;
str1[j] = ' ';
bad = 0;
}
}
if (bad)--chance;
if (!chance)lose = 1;
if (!lf)win = 1;
if (win || lose)
break;
}
if (win)
cout << "You win." << endl;
else if (lose)
cout << "You lose." << endl;
else
cout << "You chickened out." << endl;
}
int main()
{
int n;
while (cin >> n)
{
char str1[500], str2[500];
if (n == -1)
return 0;
cout << "Round " << n << endl;
cin >> str1;
cin >> str2;
guess(str1, str2);
}
return 0;
}