-
Notifications
You must be signed in to change notification settings - Fork 0
/
mass-cow
70 lines (60 loc) · 1.17 KB
/
mass-cow
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
#include<stdlib.h>
#include<stdio.h>
void main() {
int mass[] = { 0,0,0,0,0 }, mass2[] = { 1,2,3,4,0 };
int input, i = 0, end = 0, mid = 0, max = 0;
int a = 0, b = 0, c = 0;
int cow = 0, bull = 0;
printf("Enter the number of digits 2 to 5:\n");
scanf("%d", &max);
srand(time(NULL));
mass[0] = 1 + rand() % 8;
for (int r = 1; r < max; r++) {
do {
c = 0;
mass[r] = rand() % 9;
for (int k = 0; k < max; k++) {
if (mass[r] == mass[k])
c++;
}
} while (c != 1);
}
do {
cow = 0;
bull = 0;
max = 0;
end = 0;
printf("Enter the number:\n");
scanf("%d", &input);
while (input>0) {
mass2[max] = input % 10;
input = input / 10;
max++;
}
mid = max - 1;
for (int r = 0; r < max / 2; r++) {
i = mass2[r];
mass2[r] = mass2[mid];
mass2[mid] = i;
mid--;
}
for (int r = 0; r < max; r++) {
if (mass[r] == mass2[r]) {
bull++;
}
for (int j = 0; j < max; j++) {
if ((mass[r] == mass2[j]) && (r != j)) {
cow++;
}
}
}
while (end < max) {
if (mass[end] == mass2[end])
end++;
else
break;
}
printf("Cows: %d Bulls: %d\n", cow, bull);
} while (end != max);
printf("WIN!!");
}