Advertisement
Skirtek

Untitled

Sep 29th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ifstream wej;
  9.     wej.open("slowa.txt");
  10.     ofstream wyj1;
  11.     ofstream wyj2;
  12.     ofstream wyj3;
  13.     wyj3.open("wynik_4_3.txt");
  14.     string slowo;
  15.     int zera=0;
  16.     int jedynki = 0;
  17.     int ilosc = 0;
  18.     int dl = 0;
  19.     int x = 0;
  20.     int il = 0;
  21.     int suma = 0;
  22.     int maxi = 0;
  23.     int seria = 0;
  24.     for(int i=0; i<1000; i++)
  25.     {
  26.         wej>>slowo;
  27.         dl = slowo.length();
  28.         jedynki = 0;
  29.         zera = 0;
  30.         x = 0;
  31.         suma = 0;
  32.         for(int y=0; y<dl; y++)
  33.         {
  34.             suma+=(slowo[y]-48);
  35.         }
  36.         if(slowo[0] == 48 && suma > 0)
  37.         {
  38.             while(x<dl)
  39.             {
  40.                 if(slowo[x] == 49)
  41.                 {
  42.                     break;
  43.                 }
  44.                 else
  45.                 {
  46.                     x++;
  47.                     continue;
  48.                 }
  49.  
  50.             }
  51.             while(x<dl)
  52.             {
  53.                 if(slowo[x] != 49)
  54.                 {
  55.                     break;
  56.                 }
  57.                 else
  58.                 {
  59.                     if(x == dl-1)
  60.                     {
  61.                         il++;
  62.                         break;
  63.                     }
  64.                     else
  65.                     {
  66.                         x++;
  67.                         continue;
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.         for(int j=0; j<dl; j++)
  73.         {
  74.  
  75.             if(slowo[j] == 48)
  76.             {
  77.                 zera++;
  78.             }
  79.             else
  80.             {
  81.                 jedynki++;
  82.             }
  83.         }
  84.         if(zera>jedynki)
  85.         {
  86.             ilosc++;
  87.         }
  88.         for(int q=0;q<dl;q++){
  89.             seria = 0;
  90.             while(slowo[q] == 48){
  91.                     seria++;
  92.                     q++;
  93.                 }
  94.                 if(seria == 10){
  95.                     wyj3<<slowo<<endl;
  96.                 }
  97.                 if(seria>maxi){
  98.                     swap(maxi,seria);
  99.                 }
  100.         }
  101.     }
  102. wyj1.open("wynik_4_1.txt");
  103.     wyj1<<ilosc;
  104.     wyj1.close();
  105.    wyj2.open("wynik_4_2.txt");
  106.    wyj2<<il;
  107.    wyj2.close();
  108.     wyj3<<"Nadluzsza seria to: "<<maxi;
  109.     wyj3.close();
  110.     cout<<"Done";
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement