-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2043-simple-bank-system.cpp
More file actions
40 lines (35 loc) · 1020 Bytes
/
2043-simple-bank-system.cpp
File metadata and controls
40 lines (35 loc) · 1020 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
class Bank {
public:
vector<long long> bal;
int n;
Bank(vector<long long>& balance) {
bal = balance;
n = bal.size();
}
bool valid_acc(int x) {
return x >= 1 && x <= n;
}
bool transfer(int a1, int a2, long long money) {
if (!valid_acc(a1) || !valid_acc(a2) || bal[a1 - 1] < money) return false;
bal[a1 - 1] -= money;
bal[a2 - 1] += money;
return true;
}
bool deposit(int a, long long money) {
if (!valid_acc(a)) return false;
bal[a - 1] += money;
return true;
}
bool withdraw(int a, long long money) {
if (!valid_acc(a) || bal[a - 1] < money) return false;
bal[a - 1] -= money;
return true;
}
};
/**
* Your Bank object will be instantiated and called as such:
* Bank* obj = new Bank(balance);
* bool param_1 = obj->transfer(account1,account2,money);
* bool param_2 = obj->deposit(account,money);
* bool param_3 = obj->withdraw(account,money);
*/