Lixard

Lab3

Mar 24th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     SetConsoleCP(1251);
  9.     SetConsoleOutputCP(1251);
  10.     int n;
  11.     cout << "Введите размер всех строк: ";
  12.     cin >> n;
  13.     cin.ignore();
  14.     char *str = new char[n];
  15.     cout << "Введите строку: ";
  16.     gets_s(str, n - 1);
  17.     char *strp = new char[n];
  18.     cout << "Введите подстроку: ";
  19.     gets_s(strp, n - 1);
  20.  
  21.     while (true)
  22.     {
  23.         char *q = strstr(str, strp);
  24.         if (q != NULL)
  25.         {
  26.             char *qp = q + strlen(strp);
  27.             strcpy_s(q, n/2, qp);
  28.         }
  29.         else break;
  30.     }
  31.     cout << "Результат удаления подстроки из строки: " << str << endl;
  32.     char *a = new char[n * 2];
  33.     for (int i = 0; i < n * 2; i++)
  34.     {
  35.         a[i] = 0;
  36.     }
  37.     for (int i = 0, j = 0; i < strlen(str); i++)
  38.     {
  39.         a[j++] = str[i];
  40.         if (str[i] == 'a')
  41.         {
  42.             a[j++] = ' ';
  43.         }
  44.     }
  45.     cout << "Результат добавления пробелов после a: " << a << endl;
  46.     char l[300] = { 0 };
  47.     cout << "Введите еще одну строку для проверки на буквы: " << endl;
  48.     gets_s(l, 299);
  49.     int y = 0;
  50.     int i = 0;
  51.     while (l[y])
  52.     {
  53.         if (isalpha(l[y]))
  54.         {
  55.             i++;
  56.         }
  57.         y++;
  58.     }
  59.     if (y == i)
  60.     {
  61.         cout << "Вся строка состоит из букв" << endl;
  62.     }
  63.     else
  64.     {
  65.         cout << "Не все символы строки являются буквами" << endl;
  66.     }
  67.     delete[] a;
  68.     delete[] str;
  69.     delete[] strp;
  70.     system("PAUSE");
  71.     return 0;
  72. }
Add Comment
Please, Sign In to add comment