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 <fstream>
#include <iomanip>
#include <cmath>
const char CDfv[] = "data.txt";
const char CRfv[] = "results.txt";
const int CMax = 24;
using namespace std;
void Read(const char fv[], int A[], int B[], double C[], int & n);
int HighestAmount(double C[], int n);
void Read(const char fv[], int A[], int B[], double C[], int & n)
{
ifstream fd(fv);
fd >> n;
for (int i = 0; i < n; i++)
fd >> A[i] >> B[i] >> C[i];
fd.close();
}
int HighestAmount(double C[], int n)
{
double max = C[0];
int maxind = 0;
for (int i = 1; i < n; i++)
if (C[i] > max) {
max = C[i];
maxind = i;
}
return maxind;
}
int main()
{
int M[CMax]; //month
int D[CMax]; //day
double K[CMax]; //mushroom amount
int n; //foraging amount
double indmax;
ofstream fr;
Read(CDfv, M, D, K, n);
fr.open(CRfv, ios::app);
indmax = HighestAmount(M, D, K, n);
fr << "HighestAmount: " << M[indmax] << D[indmax] << K[indmax] << endl;
fr.close();
return 0;
}
|