Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <ostream>
- using namespace std;
- int load()
- {
- fstream plik;
- double x[10];
- double y[10];
- plik.open("s.txt", ios_base::in);
- int n;
- plik >> n;
- char sep;
- for(int i = 0; i < n; i++)
- {
- plik >> x[i] >> sep >> y[i];
- cout << x[i] << " " << y[i] << endl;
- }
- }
- void zad1(int* a, int* b)
- {
- if(*b < *a)
- {
- int temp = *a;
- *a = *b;
- *b = temp;
- }
- }
- int mniej(int* a, int* b)
- {
- if(*a < *b)
- return *a;
- else
- return *b;
- }
- int* mniej2(int* a, int* b)
- {
- if(*a < *b)
- return a;
- else
- return b;
- }
- double suma(double* a, int n)
- {
- double s = 0;
- for(int i = 0; i < n; i++)
- {
- s += *(a+i);
- }
- return s;
- }
- int* MAX(int* tab, int n)
- {
- int c = 0;
- for(int i = 0; i < n; i++)
- {
- if(*(tab+c) < *(tab+i))
- c = i;
- }
- return tab+c;
- }
- double* NewDouble()
- {
- return new double;
- }
- double* NewTab(int Size)
- {
- return new double[Size];
- }
- double* Copy(double* tab, int n)
- {
- double* res = new double[n];
- for(int i = 0; i < n; i++)
- {
- *(res+i) = *(tab+i);
- }
- return res;
- }
- class Pierwsze
- {
- public:
- int* tab;
- Pierwsze()
- {
- tab = new int[10000];
- for(int i = 0; i < 10000; i++)
- {
- tab[i] = 0;
- }
- }
- void Display()
- {
- for(int i = 0; i < 10000; i++)
- {
- if(tab[i] != 0)
- {
- cout << i << ": " << tab[i] << endl;
- }
- }
- }
- /// n < 10 000
- void Rozklad(int n) /// rozklada n na liczby pierwsze
- {
- for(int i = 2; i <= n; i++)
- {
- while(n%i == 0)
- {
- n = n/i;
- tab[i]++;
- // cout << "dodaje+1 dla " << i << ", n=" << n*i << endl;
- }
- }
- }
- };
- int mainZAD1()
- {
- Pierwsze* results = new Pierwsze();
- int n = 10;
- n = 20;
- for(int i = 1; i <= n; i++)
- {
- results->Rozklad(i);
- }
- results->Display();
- }
- class Slowo
- {
- public:
- string slowo;
- vector<int> wiersze;
- Slowo(string slowo)
- {
- this->slowo = slowo;
- }
- void DodajWiersz(int i)
- {
- for(int j = 0; j < wiersze.size(); j++)
- {
- if(wiersze[j] == i)
- return;
- }
- wiersze.push_back(i);
- }
- void Display()
- {
- cout << slowo << " | wyst: ";
- for(int j = 0; j < wiersze.size(); j++)
- {
- cout << wiersze[j] << ", ";
- }
- cout << endl;
- }
- };
- bool Contain(string s, vector<Slowo*> V)
- {
- for(int i = 0; i < V.size(); i++)
- {
- if(V[i]->slowo == s)
- return true;
- }
- return false;
- }
- int getIndex(string s, vector<Slowo*> V)
- {
- for(int i = 0; i < V.size(); i++)
- {
- if(V[i]->slowo == s)
- if(V[i]->slowo == s)
- return i;
- }
- return -1;
- }
- vector<string> split(string text)
- {
- cout << text << endl;
- vector<string> res;
- string s = "";
- for(int i = 0; i < text.size(); i++)
- {
- if(text[i] != '.' && text[i] != ';' && text[i] != ':' && text[i] != ',')
- {
- if(text[i] != ' ')
- s += text[i];
- else
- {
- res.push_back(s);
- s = "";
- }
- }
- }
- if(s != "")
- res.push_back(s);
- return res;
- }
- int main()
- {
- vector<Slowo*> skorowidz;
- fstream plik;
- plik.open("dane.txt", ios_base::in);
- string s;
- Slowo* slowo;
- vector<string> line;
- int nrLini = 0;
- int index;
- while( getline(plik, s) )
- {
- line = split(s);
- for(int i = 0; i < line.size(); i++)
- {
- cout << line[i] << endl;
- index = getIndex(line[i], skorowidz);
- if(index == -1)
- {
- slowo = new Slowo(line[i]);
- skorowidz.push_back(slowo);
- slowo->wiersze.push_back(nrLini);
- }
- else
- {
- skorowidz[index]->DodajWiersz(nrLini);
- }
- }
- nrLini++;
- }
- for(int i = 0; i < skorowidz.size(); i++)
- {
- skorowidz[i]->Display();
- }
- }
- int main2()
- {
- double* tab = NewTab(5);
- for(int i = 0; i < 5; i++)
- {
- tab[i] = 0.2;
- }
- cout << suma( Copy(tab, 5) , 5) << endl;
- int* a = new int(5);
- int* b = new int(1);
- cout << *a << endl;
- int c = mniej(a, b);
- cout << c << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement