Facebook
From Social Monkey, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 212
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. using namespace std;
  5. // 63.1
  6. bool checkHalves(string str){
  7.         for(int i=0; i<str.size()/2; i++)
  8.                 if(str[i]!=str[(str.size()/2)+i])
  9.                         return false;
  10.         return true;
  11. }
  12. // 63.2
  13. bool t1(string str){
  14.         for(int i=0; i<str.size(); i++)
  15.                 if(str[i]==str[i-1] && str[i]=='1')
  16.                         return false;
  17.         return true;
  18. }
  19. // 63.3
  20. int btd(string str){
  21.         int dec=0;
  22.         for(int i=0; i<str.size(); i++)
  23.                 if(str[i]=='1')
  24.                         dec+=pow(2, str.size()-i-1);
  25.         return dec;
  26. }
  27.  
  28. bool prime(int a){
  29.         for(int i=2; i<a; i++)
  30.                 if(!(a%i))
  31.                         return false;
  32.         return true;
  33. }
  34.  
  35. int main(){
  36.         ifstream ciagi("ciagi.txt");
  37.         ofstream wyniki("wyniki_ciagi.txt");
  38.         int ilosc, min, max;
  39.         string str;
  40.        
  41.         // 63.1
  42.         wyniki<<"63.1\n";
  43.         while(!ciagi.eof()){
  44.                 ciagi>>str;
  45.                 if(!(str.size()%2))
  46.                         if(checkHalves(str))
  47.                                 wyniki<<str<<endl;
  48.         }
  49.        
  50.         // 63.2
  51.         ilosc=0;
  52.         wyniki<<"\n63.2\n";
  53.         ciagi.seekg(0);
  54.         while(!ciagi.eof()){
  55.                 ciagi>>str;
  56.                 if(t1(str))
  57.                                 ilosc++;
  58.         }
  59.         wyniki<<ilosc<<endl;
  60.        
  61.        
  62.         ciagi.close();
  63.         wyniki.close();
  64.         return 0;
  65. }
  66.