Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream> //obsloga strumienia I/O
  2. #include <cmath> //funkcje matematyczne
  3. #include <string>
  4. #include <fstream> //do plików
  5. #include <ctime> //czas
  6. #include <cstdlib>
  7. #include <iomanip> // do manipulacji strimeniem wyjscia
  8.  
  9. using namespace std;
  10.  
  11. int main(){
  12.     fstream file("liczby.txt");
  13.     int parzyste = 0;
  14.     int maxD = 0;
  15.     string maxS = "";
  16.     int sl = 0;
  17.    
  18.     while(!file.eof()){
  19.         string s;
  20.         file >> s;
  21.         if(s[s.length()-1] == '0')
  22.             parzyste++;
  23.        
  24.         int n = 0;
  25.         for(int i = s.length()-1, j = 0; i >= 0; i--, j++){
  26.             n += pow(2, j) * (s[i]-'0');
  27.         }
  28.         if(maxD < n){
  29.             maxD = n;
  30.             maxS = s;
  31.         }
  32.        
  33.         if(s.length() == 9){
  34.             sl++;
  35.         }
  36.     }
  37.     cout << "Najwieksza(10): " << maxD << " (2): " << maxS << endl;
  38.     cout << parzyste << endl;
  39.     cout << "Liczby majace 9 cyfr: " << sl;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement