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* temp2 = new char[20];
- char* temp3 = new char[20];
- *temp3 = 0;
- 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;
- temp2= _strrev(str2);
- temp2 = strtok(temp2, symbol);//берем из реверсной строки подстроку до символа без него
- temp2=_strrev(str2);//обратно
- //strncat(temp1, temp2, n);//соединяем
- if (strlen(temp2) + 1 < n)
- { //СИТУАЦИЯ-ИСКЛЮЧЕНИЕ
- char* temp3 = new char[20];
- *temp3 = 0;
- strcpy(temp3, str1);
- temp1 = _strrev(temp3);
- temp1 = strstr(temp1, symbol);
- temp1 = _strrev(temp1); //здесь строка уже прямая с символом на конце*/
- strncat(temp1, temp2, n);//соединяем
- int i = strlen(str1) - strlen(temp1);//находим, сколько символов дописать в конце
- cout << i << endl;
- *temp2 = 0;//очищаем буфер
- *temp3 = 0;
- temp3 = _strrev(str1);//переворачиваем, чтобы взять символы с конца
- strncat(temp2, temp3, i);//берем символы с конца
- temp2 = _strrev(temp2);//реверс
- strncat(temp1, temp2, i);//соединяем воедино
- }
- else//ОСНОВНАЯ СИТУАЦИЯ
- {
- temp1 = _strrev(str1);
- temp1 = strstr(temp1, symbol);
- temp1 = _strrev(temp1); //здесь строка уже прямая с символом на конце
- strncat(temp1, temp2, n);//соединяем
- }
- printf("%s", temp1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement