-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathatm_machine.cpp
61 lines (52 loc) · 1.38 KB
/
atm_machine.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
51
52
53
54
55
56
57
58
59
60
61
// https://www.codechef.com/viewsolution/31269850
#include <iostream>
#include<vector>
using namespace std;
void solve_test_case()
{
long int n, money_availability, customer_widthdraw;
vector<int>client;
// Read information about the single test case
cin >> n >> money_availability;
for (int i = 0; i < n; i++)
{
cin >> customer_widthdraw;
client.push_back(customer_widthdraw);
}
for (int i = 0; i < n; i++)
{
// Case 1: NO money in the atm
if (money_availability <= 0)
{
// Print 0 for the rest of costumer and stop the execution of the checks
for (int a = i; a < n; a++)
cout << '0';
break;
}
//Case 2: There are enough money and the customer can get them
else if ((money_availability - client[i]) >= 0)
{
//Give money to the customer and so subtract its widthdra from the ATM availability
money_availability -= client[i];
cout << '1';
}
// Case 3: The request is to high
else if (client[i] > money_availability)
{
cout << '0';
}
}
}
int main()
{
// number of test cases
int t = 1;
// Read number of test cases
cin >> t;
for (int i = 0; i < t; i++)
{
solve_test_case();
cout << "\n";
}
return 0;
}