d2jsp
Log InRegister
d2jsp Forums > Off-Topic > International > Magyar > Első Adatszerkezetek és Algoritmusok Házim
1239Next
Closed New Topic New Poll
Member
Posts: 35,964
Joined: Dec 27 2007
Gold: 0.00
Sep 16 2012 12:43pm
Code
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int preload()
{
   ifstream input;
   input.open("in.txt");
   int n;
   int m;
   input >> n >> m;
   input.close();
   return n*m;
}

void loadfv(int* const &t)
{
   ifstream input;
   input.open("in.txt");
   int n;
   int m;
   input >> n >> m;
   for (int a = 0; a < n; a++)
   {
       for (int b = 0; b < m; b++)
       {
           input >> t[a+n*b];
       }
   }
   input.close();
}

double atlagfv(const int* const &t,const int* const &length)
{
   double a = 0;
   for (int z = 0; z < *length; z++)
   {
       a += t[z];
   }
   a = a/ *length;
   return a;
}

int minfv(const int* const &t,const int* const &length)
{
   int a = t[0];
   for (int z = 0; z < *length; z++)
   {
       if (a > t[z])
       {
           a = t[z];
       }
   }
   return a;
}

int maxfv(const int* const &t,const int* const &length)
{
   int a = t[0];
   for (int z = 0; z < *length; z++)
   {
       if (a < t[z])
       {
           a = t[z];
       }
   }
   return a;
}

double elteresfv(const int* const &t,const int* const &length,double* &atlag)
{
   double a = 0;
   for (int z = 0; z < *length; z++)
   {
       a = a+abs(t[z]-*atlag);    // remélem ezt jó képlettel számoltam
   }
   a = a/ *length;
   return a;
}

void kiiras(const double * const &atlag,const int * const &min,const int * const &max,const double * const &elteres)
{
   ofstream myfile;
   myfile.open ("out.txt");
   myfile << *atlag << endl;
   myfile << *min << endl;
   myfile << *max << endl;
   myfile << *elteres << endl;
   myfile.close();
}

int main()
{
   int *length = new int(preload()); // azért csináltam külön ezt, mert ha a load függvényben deklaráltam a t-t, akkor nem volt jó
   int *t = new int[*length];  // felteszem, hogy az elemek egész számok lesznek
   loadfv(t);
   double *atlag = new double(atlagfv(t,length));
   int *min = new int(minfv(t,length));
   int *max = new int(maxfv(t,length));
   double *elteres = new double(elteresfv(t,length,atlag));
   kiiras(atlag,min,max,elteres);
   delete[] t;
   delete length;
   delete atlag;
   delete min;
   delete max;
   delete elteres;
}


+1

This post was edited by xGurke on Sep 16 2012 12:55pm
Member
Posts: 26,945
Joined: Jan 31 2012
Gold: 411.00
Sep 16 2012 12:43pm
nem rossz
Member
Posts: 35,964
Joined: Dec 27 2007
Gold: 0.00
Sep 16 2012 12:43pm
nem rossz
Member
Posts: 46,130
Joined: Aug 22 2006
Gold: 85,930.00
Sep 16 2012 12:44pm
>implying erdekel
Member
Posts: 35,964
Joined: Dec 27 2007
Gold: 0.00
Sep 16 2012 12:45pm
>implying erdekel
Member
Posts: 45,902
Joined: Oct 8 2006
Gold: 59.00
Sep 16 2012 12:46pm
>implying nem rossz
Member
Posts: 35,964
Joined: Dec 27 2007
Gold: 0.00
Sep 16 2012 12:47pm
>implying nem rossz
Member
Posts: 19,706
Joined: Jul 30 2006
Gold: 0.00
Sep 16 2012 12:47pm
ccc
Member
Posts: 26,945
Joined: Jan 31 2012
Gold: 411.00
Sep 16 2012 12:48pm
nem ccc
Member
Posts: 45,902
Joined: Oct 8 2006
Gold: 59.00
Sep 16 2012 12:49pm
>implying gürke
Go Back To Magyar Topic List
1239Next
Closed New Topic New Poll