Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- int liczR(char name[]){
- ifstream p;
- string tmp;
- int i=0;
- p.open(name);
- while(p.good())
- {
- getline(p,tmp);
- i++;
- }
- p.close();
- return i;
- }
- int liczC(char name[]){
- ifstream p;
- char c;
- int i=0,tmp;
- p.open(name);
- while(p.good())
- {
- p >> tmp;
- p.get(c);
- i++;
- if(c=='\n')break;
- }
- p.close();
- return i;
- }
- int** generuj(int R, int C){
- int **tmp;
- tmp = new int *[R];
- for (int i = 0; i < R; i++)
- tmp[i] = new int [C];
- return tmp;
- }
- //czytaj
- int** czytaj(char name[],int*R,int*C){
- int** tmp;
- ifstream p;
- *R=liczR(name);
- *C=liczC(name);
- tmp=generuj(*R,*C);
- p.open(name);
- for(int i=0;i<*R;i++){
- for(int j=0;j<*C;j++){
- p>>tmp[i][j];
- p.get();//przeskakuje o jeden zank
- }
- }
- p.close();
- return tmp;
- }
- //oblicz
- void oblicz(float*wsk,int**tab,int R,int C,int S){
- for(int i=0;i<49;i++) wsk[i]=0;
- for(int i=0;i<R;i++)
- for(int j=S-1;j<C;j++)
- wsk[tab[i][j]-1]++;
- for(int i=0;i<49;i++)
- wsk[i]/=R/100;
- }
- //extrema
- void extrema(float*wsk,float*wmin,float*wmax){
- float tmp,ymax=0,ymin=100;
- for(int=0;i<49;i++){
- temp=wsk[i];
- if(tmp<ymin) ymin=tmp;
- if(tmp>ymax) ymax=tmp;
- }
- *wmin=wmin;
- *wmax=wmax;
- }
- //zapisz
- int main(){
- int **tab, R,C;
- float *wsk, wynik[49],wmin,wmax;
- char fileO[]={"lotto.csv"};
- char fileZ[]={"wyniki.csv"};
- wsk=wynik;
- tab = czytaj(fileO,&R,&C);
- /*for(int i=0;i<R;i++){
- for(int j=0;j<C;j++){
- cout<<tab[i][j]<<";";
- }
- cout<<endl;
- }
- *///wyswietla zawartość
- oblicz(wsk,tab,R,C,5);
- for(int i=0;i<49;i++){
- cout<<i+1<<"->"<<wynik[i]<<"%"<<endl;
- }
- extrema(wsk, &wmin, &wmax);
- cout<<"minimum:"<<wmin<<"~"<<floor(wmin)<<endl;
- count<<"maksimum:"<<wmax<<"~"ceil(wmax)<<endl;
- //floor(), ceil() zaokragla w dol iw gore
- //TUTAJ JESZCZE WYŚWIETLANIE W KONSOLI :)
- /*
- if(zapisz(wsk,fileZ)==0)
- cout << endl << "SAVE SUKCES" << endl;
- else
- cout << "SAVE ERROR" << endl;
- */
- delete [] tab;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement