Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- char* str1 = new char[12];
- char* str2 = new char[10];
- char* temp1 = new char[20];
- char* symbol = new char;
- int n;
- cout << "Enter str1: " << endl;
- cin >> str1;
- cout << "Enter str2: " << endl;
- cin >> str2;
- cout << "Enter symbol: " << endl;
- cin >> symbol;
- cout << "Enter n: " << endl;
- cin >> n;
- _strrev(str2);
- str2 = strtok(str2, symbol);//берем из реверсной строки подстроку до символа без него
- _strrev(str2);//обратно
- int a = strlen(str1);
- int b = strlen(str2);
- if (b >= n)
- {
- b = n-1;//количество символов из строки 2,на которое мы заменяем
- }
- *temp1 = 0;
- strcpy(temp1, str1);
- _strrev(temp1);
- temp1 = strstr(temp1, symbol);
- _strrev(temp1); //здесь строка уже прямая с символом на конце*/
- int i = a - strlen(temp1) - b;//находим, сколько символов дописать в конце
- strcat(temp1, str2);//соединяем
- if (strlen(temp1) < a)
- {
- *str2 = 0;//очищаем
- _strrev(str1);//переворачиваем, чтобы взять символы с конца
- strncat(str2, str1, i);//берем символы с конца
- _strrev(str2);//реверс
- strncat(temp1, str2, i);//соединяем воедино
- }
- printf("%s", temp1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement