Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <math.h>
- #include <windows.h>
- #include <string.h>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include <cmath>
- #include <utility>
- #include <map>
- using namespace std;
- void wyswietlWektor(vector<int> &wektor)
- {
- cout << endl << "INSTANCJA: DLUGOSC INSTANCJI: " << wektor.size() << endl;
- for(int i = 0; i < wektor.size(); i++)
- {
- cout << wektor[i] << " ";
- }
- }
- void wczytaj(vector<int> &wczytanaInstancja)
- {
- string fileName;
- string fullFileName;
- cout << endl << "PODAJ NAZWE PLIKU (BEZ .TXT): ";
- getline(cin >> ws, fileName);
- fullFileName = fileName + ".txt";
- ifstream instancjaMapy(fullFileName);
- if(!instancjaMapy.is_open())
- {
- cout << "BLAD";
- exit(1);
- }
- string linia;
- string liczba;
- getline(instancjaMapy, linia);
- stringstream podzieloneLiczby(linia);
- while(podzieloneLiczby >> liczba)
- {
- wczytanaInstancja.push_back(stoi(liczba));
- }
- }
- long long int silnia(int liczba)
- {
- long long int wynik = 1;
- for(int i = 1; i <= liczba; i++)
- {
- wynik = wynik * i;
- }
- return wynik;
- }
- long long int symbolNewtona(int gornaLiczba, int dolnaLiczba)
- {
- return silnia(gornaLiczba) / (silnia(dolnaLiczba) * silnia(gornaLiczba - dolnaLiczba));
- }
- int sprawdzenieDlugosci(vector<int> &wczytanaInstancja)
- {
- int dlugoscInstancji = wczytanaInstancja.size();
- for(int k = 1; k < 20; k++)
- {
- if(symbolNewtona(k+2, 2) == dlugoscInstancji)
- {
- return k;
- }
- }
- return 0;
- }
- int obliczRoznice(vector<int> &wczytanaInstancja, int &roznica)
- {
- int max1 = wczytanaInstancja[0];
- int max2 = wczytanaInstancja[0];
- for(auto i: wczytanaInstancja)
- {
- if(i > max1)
- {
- max2 = max1;
- max1 = i;
- }
- else if(i > max2)
- {
- max2 = i;
- }
- }
- cout << endl << "PIERWSZA NAJWIEKSZA: " << max1;
- cout << endl << "DRUGA NAJWIEKSZA: " << max2;
- roznica = max1 - max2;
- return roznica;
- }
- // void szukaj(int roznica,int ind,int &czyJest)
- // {
- // //...
- // if(ind==maxind)
- // {
- // <wypisz rozwiązanie>
- // czyJest=1;
- // }
- // else // for (...)
- // {
- // //...
- // if(<warto kontynuować bieżące rozwiązanie>)
- // {
- // szukaj(roznica,ind+1,czyJest);
- // }
- // if(czyJest==1)
- // {
- // break;
- // }
- // //...
- // }
- // }
- int main()
- {
- int ind = 0;
- int czyJest = 0;
- int roznica = 0;
- int liczbaCiec = 0;
- vector<int> wczytanaInstancja;
- wczytaj(wczytanaInstancja);
- wyswietlWektor(wczytanaInstancja);
- liczbaCiec = sprawdzenieDlugosci(wczytanaInstancja);
- if(liczbaCiec == 0)
- {
- cout << endl << "DLUGOSC INSTANCJI JEST NIEPOPRAWNA";
- exit(1);
- }
- else
- {
- cout << endl << "LICZBA CIEC: " << liczbaCiec;
- }
- obliczRoznice(wczytanaInstancja, roznica);
- cout << endl << "ROZNICA: " << roznica;
- // szukaj(roznica,ind+1,czyJest);
- if(czyJest == 0)
- {
- cout << endl << "NIE MA ROZWIAZANIA";
- }
- cout << endl << "DZIALA JAK NARAZIE";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment