Advertisement
patryk178

Untitled

Feb 9th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     ifstream fin("liczby.txt");
  9.     int ile = 0;
  10.     int ilePrzez2 = 0;
  11.     int ilePrzez8 = 0;
  12.     while(!fin.eof())
  13.     {
  14.         string liczba;
  15.         fin>>liczba;
  16.         int ile0 = 0;
  17.         int ile1 = 0;
  18.         for(int i=0;i<liczba.size();i++)
  19.         {
  20.             if(liczba[i]=='0')ile0++;
  21.         }
  22.  
  23.         ile1 = liczba.size()-ile0;
  24.         if(ile0>ile1)ile++;
  25.  
  26.  
  27.         if(liczba.at(liczba.size()-1)=='0')ilePrzez2++;
  28.         if(liczba.size()>3)
  29.         {
  30.             if(liczba.at(liczba.size()-1)=='0' && liczba.at(liczba.size()-2)=='0' && liczba.at(liczba.size()-3)=='0')ilePrzez8++;
  31.         }
  32.     }
  33.  
  34.     cout<<"1: "<<ile<<endl;
  35.     cout<<"2: "<<ilePrzez2<<endl<<"   "<<ilePrzez8;
  36.  
  37.  
  38.  
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement