vertc

05-06

Jun 5th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>     //dane: https://pastebin.com/qpb9EhWb
  2. #include <fstream>
  3. #include <math.h>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     ifstream IN("liczby.txt");
  10.     string bin;
  11.     int size, dec, parzyste=0, max=0, cyfr9=0;
  12.     while (IN >> bin) {
  13.         size = bin.length();
  14.         dec = 0;
  15.         if (size == 9) {
  16.             cyfr9++;
  17.         }
  18.         if (bin[size - 1] == '0') {
  19.             parzyste++;
  20.         }
  21.         for (int i = 0; i < size; i++) {
  22.             if (bin[size - 1 - i] == '1') {
  23.                 dec += pow(2, i);
  24.             }
  25.         }
  26.         max = dec > max ? dec : max;
  27.     }
  28.    
  29.     cout << "Liczba parzystych liczb to: " <<parzyste<< endl;
  30.     cout << "Najwieksza liczba to: " << max << "(10), ";
  31.     int max_bin = max;  
  32.     while (max_bin != 0) {
  33.         cout << max_bin % 2;
  34.         max_bin = (max_bin - max_bin % 2) / 2;
  35.     }
  36.     cout << "(2)" << endl;
  37.    
  38.     cout << "Ilosc 9-cyfrowych liczb to: " << cyfr9 << "(10), ";
  39.     while (cyfr9 != 0) {
  40.         cout << cyfr9 % 2;
  41.         cyfr9 = (cyfr9 - cyfr9 % 2) / 2;
  42.     }
  43.     cout << "(2)" << endl;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment