Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstring>
- #include<cstdio>
- #include<cstdlib>
- #include<iostream>
- #define _CRT_SECURE_NO_WARNINGS
- class Olala
- {
- private:
- char* str;
- public:
- Olala()
- {
- str = new char[1];
- str[0] = '\0';
- }
- void print()
- {
- std::cout << "Vivod stroki " << str << "\n";
- }
- Olala(char *s)
- {
- str = new char[strlen(s) + 1];
- strcpy(str, s);
- }
- Olala(Olala& olala)
- {
- str = new char[strlen(olala.str) + 1];
- strcpy(str, olala.str);
- }
- Olala& operator=(Olala & ol)
- {
- if (!str[0])
- {
- delete[] str;
- }
- str = new char[strlen(ol.str) + 1];
- strcpy(str, ol.str);
- return *this;
- }
- ~Olala()
- {
- std::cout << "destructor" << "\n";
- delete[] str;
- }
- int Perev(int m)
- {
- char buff[255];
- int n = 0, z = 0, all = strlen(str);
- while (str[n])
- if (m == 0)
- {
- while (str[n] != ' ')
- {
- buff[n] = str[n];
- ++n;
- }
- break;
- }
- else
- {
- if (str[n] == ' ') --m;
- ++n;
- }
- if (m > 0)
- {
- std::cout << "net slov";
- return 0;
- }
- else buff[n + 1] = '\0';
- m = strlen(buff);
- n = 0;
- while (n < all)
- {
- for (int i = n; (str[n] != ' '); --i)
- {
- if (str[n] == buff[i])
- {
- n++;
- m--;
- }
- else
- {
- while (str[n] != ' ') n++;
- m = strlen(buff);
- break;
- }
- if (m == 0)
- {
- m = strlen(buff);
- z++;
- n++;
- }
- }
- while (str[n] == ' ')
- n++;
- }
- std::cout << "Kol-vo " << z;
- return z;
- }
- };
- int main()
- {
- Olala M("ab ba ba f");
- M.Perev(0);
- system("pause");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement