-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgastosBolsaMonitoria.cpp
75 lines (62 loc) · 1.69 KB
/
gastosBolsaMonitoria.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <locale.h>
#include <algorithm>
#include <string>
#include <vector>
#include <sstream>
#include <iomanip>
using namespace std;
void mySplit(string line, vector<string> &input){
istringstream stream(line);
for(string s; stream >> s; ){
input.push_back(s);
}
}
void createEvent(vector<string> input, string &event){
event="";
for(int i=1; i < input.size()-2; i++){
event += input[i] + " ";
}
event += input[input.size()-2];
}
void dayHandler(vector<string> input, int &lastDay, int &maxDays){
int today = stoi(input[0]);
int days = today - lastDay - 1;
if(days > maxDays){
maxDays = days;
}
lastDay = today;
}
void costCheck(vector<string> input, double &balance, double &maxCost, string event, string &maxEvent){
double currentBalance = stod(input[input.size()-1]);
double cost = balance - currentBalance;
balance = currentBalance;
if(cost > maxCost){
maxCost = cost;
maxEvent = event;
}
}
void commaCout(double maxCost){
string costString = to_string(maxCost);
replace(costString.begin(), costString.end(), '.', ',');
string costString2 = costString.substr(0, costString.find(',')+3);
cout << costString2 << endl;
}
int main(){
setlocale(LC_ALL, "");
vector <string> input;
string line, event, maxEvent;
int lastDay=0, maxDays=0;
double balance = 1200, maxCost = -1;
while(getline(cin, line)){
mySplit(line, input);
createEvent(input, event);
dayHandler(input, lastDay, maxDays);
costCheck(input, balance, maxCost, event, maxEvent);
input.clear();
}
cout << "MAIOR: " << maxEvent << " ";
commaCout(maxCost);
cout << "DIAS: " << maxDays << endl;
return 0;
}