Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- int main()
- {
- ifstream myfile("liczby.txt");
- if( !myfile.is_open() || !myfile.good() ){
- cout << "ERROR!"; exit(0);
- }
- long long unsigned suma=0, w=0, m=0; //w-największa liczba; m-najmniejsza liczba
- unsigned najm=1, najw=1, linia=1; //najm-nr linii najmniejszej liczby; najw-nr linii największej liczby
- string liczba;
- int ile2=0, ile8=0;
- while( myfile >> liczba ){
- suma=0;
- unsigned short potega = liczba.length();
- for(short i=0; i<potega; i++){
- if(liczba[i] == '1'){
- suma += pow(2,potega-i-1);
- }
- }
- if(linia==1) { m = w = suma; }
- if( suma%2 == 0 ) ile2++;
- if( suma%8 == 0 ) ile8++;
- if( suma > w ) { w=suma; najw=linia; }
- if( suma < m ) { m=suma; najm=linia; }
- linia++;
- }
- cout << "Przez 2: " << ile2 << endl;
- cout << "Przez 8: " << ile8 << endl;
- cout << "Najwieksza: " << najw << endl;
- cout << "Najmniejsza: " << najm << endl;
- myfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement