Advertisement
VictoriaLodochkina

lab 3 5varityes

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