Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include<cstring>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<iostream>
  5.  
  6. #define _CRT_SECURE_NO_WARNINGS
  7. class Olala
  8. {
  9. private:
  10.     char* str;
  11. public:
  12.     Olala()
  13.     {
  14.         str = new char[1];
  15.         str[0] = '\0';
  16.  
  17.     }
  18.  
  19.     void print()
  20.     {
  21.         std::cout << "Vivod stroki " << str << "\n";
  22.     }
  23.  
  24.     Olala(char *s)
  25.     {
  26.         str = new char[strlen(s) + 1];
  27.         strcpy(str, s);
  28.     }
  29.  
  30.     Olala(Olala& olala)
  31.     {
  32.         str = new char[strlen(olala.str) + 1];
  33.         strcpy(str, olala.str);
  34.     }
  35.  
  36.     Olala& operator=(Olala & ol)
  37.     {
  38.         if (!str[0])
  39.         {
  40.             delete[] str;
  41.         }
  42.  
  43.         str = new char[strlen(ol.str) + 1];
  44.         strcpy(str, ol.str);
  45.  
  46.         return *this;
  47.     }
  48.  
  49.     ~Olala()
  50.     {
  51.         std::cout << "destructor" << "\n";
  52.         delete[] str;
  53.  
  54.     }
  55.  
  56.     int Perev(int m)
  57.     {
  58.         char buff[255];
  59.         int  n = 0, z = 0, all = strlen(str);
  60.  
  61.         while (str[n])
  62.             if (m == 0)
  63.             {
  64.                 while (str[n] != ' ')
  65.                 {
  66.                     buff[n] = str[n];
  67.                     ++n;
  68.                 }
  69.                 break;
  70.             }
  71.             else
  72.             {
  73.                 if (str[n] == ' ') --m;
  74.                 ++n;
  75.             }
  76.         if (m > 0)
  77.         {
  78.             std::cout << "net slov";
  79.             return 0;
  80.         }
  81.         else buff[n + 1] = '\0';
  82.  
  83.         m = strlen(buff);
  84.         n = 0;
  85.        
  86.         while (n < all)
  87.         {
  88.             for (int i = n; (str[n] != ' '); --i)
  89.             {
  90.                 if (str[n] == buff[i])
  91.                 {
  92.                     n++;
  93.                     m--;
  94.                 }
  95.                 else
  96.                 {
  97.                     while (str[n] != ' ') n++;
  98.                     m = strlen(buff);
  99.                     break;
  100.                 }
  101.                 if (m == 0)
  102.                 {
  103.                     m = strlen(buff);
  104.                     z++;
  105.                     n++;
  106.                 }
  107.             }
  108.             while (str[n] == ' ')
  109.                 n++;
  110.         }
  111.         std::cout << "Kol-vo " << z;
  112.         return z;
  113.     }
  114.  
  115. };
  116.  
  117.  
  118. int main()
  119. {
  120.     Olala M("ab ba ba f");
  121.     M.Perev(0);
  122.  
  123.  
  124.  
  125.     system("pause");
  126.     return 1;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement