-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path6062+Design an ATM Machine.cpp
More file actions
46 lines (33 loc) · 1006 Bytes
/
6062+Design an ATM Machine.cpp
File metadata and controls
46 lines (33 loc) · 1006 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
using ll = long long;
class ATM {
public:
int money[5] = {20, 50, 100, 200, 500};
ATM() : vec(5) {
}
void deposit(vector<int> banknotesCount) {
for (int i = 0; i < 5; ++i)
vec[i] += banknotesCount[i];
}
vector<int> withdraw(int amount) {
vector<int> res(5);
for (int i = 4; i >= 0; --i) {
ll nCnt = amount / money[i];
ll realCnt = min(nCnt, vec[i]);
res[i] = realCnt;
amount = amount - realCnt * money[i];
}
if (amount != 0) return {-1};
for (int i = 0; i < 5; ++i)
vec[i] -= res[i];
return res;
}
private:
vector<ll> vec;
};
//[null, null, [0,0,1,0,1], null, [-1], [0,1,0,0,1]]
/**
* Your ATM object will be instantiated and called as such:
* ATM* obj = new ATM();
* obj->deposit(banknotesCount);
* vector<int> param_2 = obj->withdraw(amount);
*/