题目链接如下:
题目中有这么一句:“Each unique wrong guess only counts against the contestant once.” 修改后的代码如下(估计题目测试集有点问题?这一句感觉没测出来):
#include <cstdio>
#include <string.h>
#include <set>
const int maxx = 1000;
int rnd, tot;
char a[maxx], b[maxx];
bool flag;
int main(){
while(scanf("%d", &rnd) == 1 && rnd != -1){
printf("Round %d\n", rnd);
scanf("%s %s", a, b);
tot = 7;
std::set<char> st, guessed;
flag = false;
for(int i = 0; i < strlen(a); ++i){
st.insert(a[i]);
}
for(int i = 0; i < strlen(b); ++i){
if(st.find(b[i]) != st.end()){
st.erase(b[i]);
if(st.empty()){
printf("You win.\n");
flag = true;
break;
}
} else if(guessed.find(b[i]) == guessed.end()){
tot--;
guessed.insert(b[i]);
if(tot == 0){
printf("You lose.\n");
flag = true;
break;
}
}
}
if(flag){
continue;
}
printf("You chickened out.\n");
}
return 0;
}
我原来的代码如下(能AC):
#include <cstdio>
#include <string.h>
#include <set>
const int maxx = 1000;
int rnd, tot;
char a[maxx], b[maxx];
bool flag;
int main(){
while(scanf("%d", &rnd) == 1 && rnd != -1){
printf("Round %d\n", rnd);
scanf("%s %s", a, b);
tot = 7;
std::set<char> st;
flag = false;
for(int i = 0; i < strlen(a); ++i){
st.insert(a[i]);
}
for(int i = 0; i < strlen(b); ++i){
if(st.find(b[i]) != st.end()){
st.erase(b[i]);
if(st.empty()){
printf("You win.\n");
flag = true;
break;
}
} else{
tot--;
if(tot == 0){
printf("You lose.\n");
flag = true;
break;
}
}
}
if(flag){
continue;
}
printf("You chickened out.\n");
}
return 0;
}