File tree Expand file tree Collapse file tree 3 files changed +144
-0
lines changed Expand file tree Collapse file tree 3 files changed +144
-0
lines changed Original file line number Diff line number Diff line change 1
1
* .out
2
2
* .exe
3
3
* .o
4
+ * .iml
5
+ .idea
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ #define MAXN 105
5
+
6
+ int n;
7
+ char solution[MAXN];
8
+ char guess[MAXN];
9
+
10
+ int flag[MAXN];
11
+
12
+
13
+ void play (){
14
+
15
+ memset (flag, 0 , sizeof (flag));
16
+
17
+ int i, j;
18
+ int wrong = 0 ;
19
+
20
+ for (i=0 ; i<strlen (guess); i++){
21
+
22
+ bool iswrong = true ;
23
+
24
+ char * pch = strchr (guess, guess[i]);
25
+ if (pch != NULL && pch-guess == i){
26
+ for (j=0 ; j<strlen (solution); j++){
27
+
28
+ if (flag[j]==0 && solution[j]==guess[i]){
29
+ flag[j] = 1 ;
30
+ iswrong = false ;
31
+ }
32
+ }
33
+
34
+ if (iswrong){
35
+ wrong++;
36
+ }
37
+
38
+ if (wrong >= 7 ){
39
+ break ;
40
+ }
41
+ }
42
+ }
43
+
44
+ printf (" Round %d\n " , n);
45
+
46
+ int k = 0 ;
47
+ for (k=0 ; k<strlen (solution); k++){
48
+ if (flag[k] == 0 ){
49
+ if (wrong < 7 ){
50
+ printf (" You chickened out.\n " );
51
+ return ;
52
+ }
53
+ else {
54
+ printf (" You lose.\n " );
55
+ return ;
56
+ }
57
+ }
58
+ }
59
+
60
+ if (k == strlen (solution)){
61
+ printf (" You win.\n " );
62
+ }
63
+ }
64
+
65
+
66
+ int main () {
67
+
68
+
69
+ while (scanf (" %d" , &n)==1 && (n!=-1 )){
70
+
71
+ memset (solution, ' \0 ' , sizeof (solution));
72
+ memset (guess, ' \0 ' , sizeof (guess));
73
+ scanf (" %s%s" , solution, guess);
74
+ play ();
75
+ }
76
+
77
+
78
+ return 0 ;
79
+
80
+ }
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ #define MAXN 105
5
+
6
+ int n;
7
+ char solution[MAXN], guess[MAXN];
8
+ int flag[MAXN];
9
+
10
+ void play () {
11
+ memset (flag, 0 , sizeof (flag));
12
+
13
+ int i, j, k, wrong = 0 ;
14
+ for (i=0 ; i<strlen (guess); i++){
15
+
16
+ bool isWrong = true ;
17
+
18
+ for (j=0 ; j<strlen (solution); j++) {
19
+ if (flag[j]==0 && solution[j] == guess[i]){
20
+ flag[j] = 1 ;
21
+ isWrong = false ;
22
+ }
23
+ }
24
+
25
+ if (isWrong){
26
+ wrong++;
27
+ }
28
+
29
+ if (wrong >= 7 ){
30
+ break ;
31
+ }
32
+ }
33
+
34
+ printf (" Round %d\n " , n);
35
+ for (k=0 ; k < strlen (solution); k++){
36
+ if (flag[k] == 0 ){
37
+ if (wrong < 7 ){
38
+ printf (" You chickened out.\n " );
39
+ return ;
40
+ } else {
41
+ printf (" You lose.\n " );
42
+ return ;
43
+ }
44
+ }
45
+ }
46
+
47
+ if (k== strlen (solution))
48
+ printf (" You win.\n " );
49
+ }
50
+
51
+
52
+ int main () {
53
+
54
+ while ( scanf (" %d" ,&n)==1 && n!=-1 ){
55
+ memset (solution, ' \0 ' , sizeof (solution));
56
+ memset (guess, ' \0 ' , sizeof (guess));
57
+ scanf (" %s%s" , solution, guess);
58
+ play ();
59
+ }
60
+
61
+ return 0 ;
62
+ }
You can’t perform that action at this time.
0 commit comments