Advertisement
VictoriaLodochkina

lab 3 z1 3 variety

Feb 23rd, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 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.     *temp3 = 0;
  15.     char* symbol = new char;
  16.     int n;
  17.     cout << "Enter str1: " << endl;
  18.     cin >> str1;
  19.     cout << "Enter str2: " << endl;
  20.     cin >> str2;
  21.     cout << "Enter symbol: " << endl;
  22.     cin >> symbol;
  23.     cout << "Enter n: " << endl;
  24.     cin >> n;
  25.     temp2= _strrev(str2);
  26.     temp2 = strtok(temp2, symbol);//берем из реверсной строки подстроку до символа без него
  27.     temp2=_strrev(str2);//обратно
  28.     //strncat(temp1, temp2, n);//соединяем
  29.     if (strlen(temp2) + 1 < n)
  30.     {   //СИТУАЦИЯ-ИСКЛЮЧЕНИЕ
  31.         char* temp3 = new char[20];
  32.         *temp3 = 0;
  33.         strcpy(temp3, str1);
  34.         temp1 = _strrev(temp3);
  35.         temp1 = strstr(temp1, symbol);
  36.         temp1 = _strrev(temp1); //здесь строка уже прямая с символом на конце*/
  37.         strncat(temp1, temp2, n);//соединяем
  38.         int i = strlen(str1) - strlen(temp1);//находим, сколько символов дописать в конце
  39.         cout << i << endl;
  40.         *temp2 = 0;//очищаем буфер
  41.         *temp3 = 0;
  42.         temp3 = _strrev(str1);//переворачиваем, чтобы взять символы с конца
  43.         strncat(temp2, temp3, i);//берем символы с конца
  44.         temp2 = _strrev(temp2);//реверс
  45.         strncat(temp1, temp2, i);//соединяем воедино
  46.     }
  47.     else//ОСНОВНАЯ СИТУАЦИЯ
  48.     {
  49.         temp1 = _strrev(str1);
  50.         temp1 = strstr(temp1, symbol);
  51.         temp1 = _strrev(temp1); //здесь строка уже прямая с символом на конце
  52.         strncat(temp1, temp2, n);//соединяем
  53.     }
  54.     printf("%s", temp1);
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement