Advertisement
VictoriaLodochkina

lab 3 z1 last

Feb 24th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     char* str1 = new char[12];
  8.     char* str2 = new char[10];
  9.     char* temp1 = new char[20];
  10.     char* symbol = new char;
  11.     int n;
  12.     cout << "Enter str1: " << endl;
  13.     cin >> str1;
  14.     cout << "Enter str2: " << endl;
  15.     cin >> str2;
  16.     cout << "Enter symbol: " << endl;
  17.     cin >> symbol;
  18.     cout << "Enter n: " << endl;
  19.     cin >> n;
  20.     _strrev(str2);
  21.     str2 = strtok(str2, symbol);//берем из реверсной строки подстроку до символа без него
  22.     _strrev(str2);//обратно
  23.     int a = strlen(str1);
  24.     int b = strlen(str2);
  25.     if (b >= n)
  26.     {
  27.         b = n-1;//количество символов из строки 2,на которое мы заменяем
  28.     }
  29.     *temp1 = 0;
  30.     strcpy(temp1, str1);
  31.     _strrev(temp1);
  32.     temp1 = strstr(temp1, symbol);
  33.     _strrev(temp1); //здесь строка уже прямая с символом на конце*/
  34.     int i = a - strlen(temp1) - b;//находим, сколько символов дописать в конце
  35.     strcat(temp1, str2);//соединяем
  36.     if (strlen(temp1) < a)
  37.     {
  38.         *str2 = 0;//очищаем
  39.         _strrev(str1);//переворачиваем, чтобы взять символы с конца
  40.         strncat(str2, str1, i);//берем символы с конца
  41.         _strrev(str2);//реверс
  42.         strncat(temp1, str2, i);//соединяем воедино
  43.     }
  44.     printf("%s", temp1);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement