Guest User

Untitled

a guest
May 8th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. `
  2. #include<iostream>
  3. #include<string>
  4. #include<fstream>
  5.  
  6.  
  7. int zera, jedynki, g;
  8.  
  9. using namespace std;
  10. string liczba;
  11.  
  12. int ilosczer(string)
  13. {
  14.    
  15.    
  16.     for(int i=0; i<=liczba.size(); i++)
  17.     {
  18.         if(liczba[i]=='0') zera++;
  19.         if(liczba[i]=='1') jedynki++;
  20.     }
  21.     if(zera>jedynki) return 0;
  22.     if(zera<=jedynki) return 1;
  23. }
  24.  
  25. int main()
  26. {
  27.    
  28.     zera=jedynki=g=0;
  29.  
  30.     fstream plik;
  31.    
  32.     plik.open("liczby.txt");
  33.    
  34.     while(plik.good())
  35.     {
  36.         plik>>liczba;
  37.         ilosczer(liczba);
  38.         if(ilosczer(liczba)==0) g++;
  39.        
  40.     }
  41.    
  42.    
  43.     plik.close();
  44.    
  45.     cout<<"liczb binarnych, w których jest więcej zer niż jedynek jest: "<<g;
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment