-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module_1_Project_DigitalWalletManagementSystem.cpp
50 lines (43 loc) · 1.28 KB
/
Module_1_Project_DigitalWalletManagementSystem.cpp
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
#include<iostream>
#include<map>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
bool compareByBalance(const pair<int, int>& a,const pair<int, int>& b) {
return a.second < b.second;
}
int main(){
int n; cin>>n;
map<int, int> users;
for(int i=0;i<n;i++){
int accountNumber, balance;
cin>>accountNumber>>balance;
users.insert({accountNumber, balance});
}
int t;
cin>>t;
map<int, pair<int, long>> transactions;
for(int i= 0;i<t;i++){
int senderAccount, resAccount; cin>>senderAccount>>resAccount;
long amountToSend; cin>>amountToSend;
transactions.insert({senderAccount, {resAccount, amountToSend}});
auto it = users.find(senderAccount);
auto resIt = users.find(resAccount);
if(it->second > amountToSend){
cout<<"Success"<<endl;
it->second -= amountToSend;
resIt->second += amountToSend;
}
else {
cout<<"Failure"<<endl;
}
}
cout<<endl;
vector<pair<int, int>> sortedUsers(users.begin(), users.end());
sort(sortedUsers.begin(), sortedUsers.end(), compareByBalance);
for (const auto& user : sortedUsers) {
cout << user.first << " " << user.second << endl;
}
return 0;
}