-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknightsOfTerror.c
72 lines (67 loc) · 1.55 KB
/
knightsOfTerror.c
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
//Problem : Knights of Terror
//Language : C
//Compiled Using : GCC
//Version : GCC 4.9.1
//Input for your program will be provided from STDIN
//Print out all output from your program to STDOUT
#include <stdio.h>
typedef int bool;
#define true 1
#define false 0
int c0, c1, c2; // x, y, z
int n, m, r;
bool cont;
int min_three(int x, int y, int z) {
if (x < y && x < z) return x;
else if (y < x && y < z) return y;
else if (z < x && z < y) return z;
return 0;
}
int min_two(int x, int y) {
if (x < y) return x;
else return y;
return 0;
}
int main() {
int i;
scanf("%d", &c0);
scanf(" %d", &c1);
scanf(" %d", &c2);
scanf(" %d", &n);
cont = true;
while(cont) {
m = 0;
if(min_three(c0, c1, c2) == c0) m = 0;
else if(min_three(c0, c1, c2) == c1) m = 1;
else m = 2;
if(m == 0) {
if(((c1 - n) <= 0) || ((c2 - n) <= 0)) {
r += min_two(c1, c2);
cont = false;
}
c1 -= n;
c2 -= n;
}
if(m == 1) {
if(((c0 - n) <= 0) || ((c2 - n) <= 0)) {
r += min_two(c0, c2);
cont = false;
}
c0 -= n;
c2 -= n;
}
if(m == 2) {
if(((c0 - n) <= 0) || ((c1 - n) <= 0)) {
r += min_two(c0, c1);
cont = false;
}
c0 -= n;
c1 -= n;
}
if(cont) {
r += n;
}
}
printf("%d", r);
return 0;
}