-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1217.cpp
More file actions
51 lines (38 loc) · 1.05 KB
/
1217.cpp
File metadata and controls
51 lines (38 loc) · 1.05 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
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;
int main() {
int testes;
double preco, total = 0, kg, qtdFrutas;
string frutas, aux;
vector<string> fruta;
map<int, int> frutaPerDay;
cin >> testes;
for(int i=0; i<testes; i++){
cin >> preco;
cin.ignore();
getline(cin, frutas);
total += preco;
for(int j=0; j<=frutas.size(); j++){
if(frutas[j] == ' ' || j==frutas.size()){
fruta.push_back(aux);
aux.clear();
} else {
aux += frutas[j];
}
}
cout << "day " << i+1 << ": " << fruta.size() << " kg" << endl;
frutaPerDay[i] = fruta.size();
fruta.clear();
}
for(auto f : frutaPerDay){
qtdFrutas += f.second;
}
kg = qtdFrutas / testes;
cout << fixed << setprecision(2) << kg << " kg by day" << endl;
cout << "R$ " << fixed << setprecision(2) << total / testes << " by day" << endl;
return 0;
}