Hangman Judge
UVA - 489
题目传送门
PS.此题Udebug有毒,即使100组样例全过,但还是WA,心塞。
这是我自己的代码,悲催的WA了
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
int main()
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endiffreopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int T;while(cin>>T&&T!=-1){string s1,s2;cin>>s1>>s2;int len1=s1.size();int len2=s2.size();set<char> ss1; ss1.clear();set<char> ss2; ss2.clear();map<char,bool> m;m.clear();map<char,bool> m1;m1.clear();rep(i,0,len1-1) {ss1.insert(s1[i]);ss2.insert(s2[i]);}int size1=ss1.size();int num=0,nape,k=0;bool ju=false;rep(i,0,len2-1) {ss1.insert(s2[i]);nape=ss1.size();if(nape==size1) {if(m[s2[i]]==false) {m[s2[i]]=true;k++;if(k==size1&&num<6){ju=true;break;}}}else{ss1.erase(s2[i]);if(m1[s2[i]]==false)num++;m1[s2[i]]=true;}}cout<<"Round "<<T<<endl;if(ju) cout<<"You win."<<endl;if(k!=size1&&num<=6) cout<<"You chickened out."<<endl;if(num>6) cout<<"You lose."<<endl;}return 0;
}
下面是我找到的一个AC代码:
#include<bits/stdc++.h>
using namespace std;
int leftt,chance;//left表示还剩多少没有猜对,chance表示还有几次可以猜错
char s[200],s2[200];
int win,lose;
void guess(char ch)
{int bad=1;for(int i=0; i<strlen(s); i++){if(ch==s[i]){leftt--;s[i]=' ';bad=0;}}if(bad)chance--;if(!leftt)win=1;if(!chance)lose=1;
}
int main()
{int rnd;while(~scanf("%d",&rnd),rnd!=-1){scanf("%s %s",s,s2);printf("Round %d\n",rnd);win=lose=0;leftt=strlen(s);chance=7;for(int i=0; i<strlen(s2); i++){guess(s2[i]);if(win||lose)break;}if(win)printf("You win.\n");else if(lose)printf("You lose.\n");elseprintf("You chickened out.\n");memset(s,'\0',sizeof(s));memset(s2,'\0',sizeof(s2));}return 0;
}