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
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
//
const char duom [] = "d.txt";
const char rez [] = "r.txt";
//
void EcoVid(int km, int l, int &nr_i, double &vid, int n, int lsum, int kmsum);
//
int main()
{
ifstream in(duom);
ofstream out(rez);
int n, l, km, nr_i, kmsum = 0, lsum = 0;
double vid;
in >> n;
for(int i = 1; i <= n; i++){
in >> l >> km;
lsum += l;
kmsum += km;
EcoVid(km, l, nr_i, vid, n, lsum, kmsum);
}
out << "Geriausias pylimas buvo: " << nr_i << endl;
out << "Vidutines kuro sanaudos: " << fixed << setprecision(1) << vid << endl;
return 0;
}
//
void EcoVid(int km, int l, int &nr_i, double &vid, int n, int lsum, int kmsum){
double km_litrai, best_km_litrai = 9999;
nr_i = 0;
vid = 0;
for(int i = 1; i <= n; i++){
km_litrai = (double)l / km * 100;
if(km_litrai < best_km_litrai){
best_km_litrai = km_litrai;
nr_i = i;
}
}
vid = (double)lsum / kmsum * 100;
}
|