-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva489.cpp
More file actions
75 lines (72 loc) · 1.7 KB
/
Copy pathUva489.cpp
File metadata and controls
75 lines (72 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <math.h>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
bool inWord(string word,char ch){
for(int i=0;i<word.size();i++){
if(word[i]==ch)return true;
}
return false;
}
bool CheckUsed(vector<char> &vec,char ch){
for(int i=0;i<vec.size();i++){
if(vec[i]==ch)return true;
}
return false;
}
int main()
{
int round;
while(true){
cin>>round;
if(round==-1)break;
string solution,guesses;
cin>>solution;
cin>>guesses;
const int siz=solution.size();
bool *masiv=new bool[siz];
for(int i=0;i<siz;i++)masiv[i]=false;
int strokes=0;
vector<char> Used;
for(int i=0;i<guesses.size();i++){
if(CheckUsed(Used,guesses[i]))continue;
if(inWord(solution,guesses[i])){
for(int j=0;j<solution.size();j++){
if(solution[j]==guesses[i]){
masiv[j]=true;
}
}
}
else{
strokes++;
}
Used.push_back(guesses[i]);
}
bool win=true;
for(int i=0;i<solution.size();i++){
if(masiv[i]==false){
win=false;
break;
}
}
cout<<"Round "<<round<<endl;
if(win){
cout<<"You win."<<endl;
}
else if(strokes>=7){
cout<<"You lose."<<endl;
}
else cout<<"You chickened out."<<endl;
delete [] masiv;
}
return 0;
}