-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletterle.cpp
More file actions
51 lines (44 loc) · 1.09 KB
/
letterle.cpp
File metadata and controls
51 lines (44 loc) · 1.09 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
#include <string>
#include <iostream>
#include <unordered_set>
int main(){
std::string line;
std::string g;
std::unordered_set<char> goal;
std::getline(std::cin, g);
std::string::iterator it;
// Traverse the string
for (it = g.begin(); it != g.end(); it++) {
goal.insert(*it);
}
int i;
bool flag = false;
for(i = 0; i < 7; i++)
{
std::getline(std::cin, line);
std::string buf = "";
int arr [5] = {0,0,0,0,0};
int done = 0;
for (int i = 0; i < 5; i++) {
char curr = line.at(i);
if (curr == g.at(i)) {
arr[i] = 2;
done++;
buf.append("G");
}
else if (goal.count(curr) == 1){
arr[i] = 1;
buf.append("Y");
}
else buf.append("X");
}
if (done == 5) {
std::cout<<"WINNER";
break;
} else if(i==6){
std::cout<<"LOSER";
break;
}
std::cout<<buf<<'\n';
}
}