forked from Tushargupta9800/CSES-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleBankSysytem.cpp
More file actions
52 lines (45 loc) · 1.23 KB
/
simpleBankSysytem.cpp
File metadata and controls
52 lines (45 loc) · 1.23 KB
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
class Bank {
public:
vector<long long> bal;
Bank(vector<long long>& balance) {
for(auto a : balance){
cout << a << " ";
bal.push_back(a);
}
}
bool transfer(int account1, int account2, long long money) {
if(account1 > bal.size() || account2 > bal.size()){
return false;
}
if(bal[account1-1] < money){
return false;
}
bal[account1-1] -= money;
bal[account2-1] += money;
return true;
}
bool deposit(int account, long long money) {
if(account > bal.size()){
return false;
}
bal[account-1] += money;
return true;
}
bool withdraw(int account, long long money) {
if(account > bal.size()){
return false;
}
if(bal[account-1] < money){
return false;
}
bal[account-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);
*/