-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCoinsExchange.cpp
More file actions
82 lines (69 loc) · 941 Bytes
/
CoinsExchange.cpp
File metadata and controls
82 lines (69 loc) · 941 Bytes
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
76
77
78
79
80
81
82
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <set>
#include <cctype>
using namespace std;
class CoinsExchange {
public:
int countExchanges(int G1, int S1, int B1, int G2, int S2, int B2)
{
int ret = 0;
while (G1 < G2) {
if (S1 >= 11) {
S1 -= 11;
G1++;
ret++;
}
else if (B1 >= 11) {
B1 -= 11;
S1++;
ret++;
}
else
return -1;
}
while (S1 < S2) {
if (G1 > G2) {
G1--;
S1 += 9;
ret++;
}
else if (B1 >= 11) {
B1 -= 11;
S1++;
ret++;
}
else
return -1;
}
while (B1 < B2) {
if (G1 > G2) {
G1--;
S1 += 9;
ret++;
}
else if (S1 > S2) {
S1--;
B1 += 9;
ret++;
}
else
return -1;
}
return ret;
}
};
// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor
// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor