1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
| //---------------------------------------------------------------------------
#include <vcl.h>
#include <iostream.h>
#include <stdio.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#pragma argsused
int len(const char*s)
{int m=0;
while(*(s+m))
m++;
return m;}
int zapyataya1(char *pre,int x)
{int pos=0; int z1=0;
for (int t=0;t<len(pre);t++)
{if (pre[t]==x&&z1!=1)
{pos=t;z1++;}}
return pos;};
int zapyataya2(char *pre,int x)
{int posi=0; int z2=0;
for (int o=0;o<len(pre);o++)
{if (pre[o]==x&&z2!=2)
{posi=o;z2++;}}
return posi;}
void strreplace(char *str,const char*substr1,const char*substr2)
{int a=len(str);int b=len(substr1);int c=len(substr2);int j=0 ;
for (int i=0;i<a+1;i++)
if (*(str+i)==*(substr1+j)){*(str+i)=*(substr2+j); j++;
} if (j==b) j=0;
}
int main(int argc, char* argv[])
{SetConsoleCP(1251);
SetConsoleOutputCP(1251);
const n=200;
char c,pre[n];char x=',';char str1[n];char str2[n];char str3[n]; char v[n]="";
char *za31=new char[n]; char *za32=new char[n]; char *za33=new char[n];
do{cout<<"Какую задачу предпочитаете решить: 1(введите 1), 2(введите 2), 3(введите 3)?"<<endl;
cin>>c;
switch(c){
case '1':
{cout<<"Введите строку 1 и нажмите Enter \n";
cin.ignore(n,'\n');
cin.getline(str1,n,'\n');
cout<<"Введите строку 2 и нажмите Enter \n";
cin.getline(str2,n,'\n');
cout<<"Введите строку 3 и нажмите Enter \n";
cin.getline(str3,n,'\n');
int d=strlen(str2)-strlen(strstr(str2,str1));
strcat(strncpy(v,str2,d),strrev(str3));
cout<<"Получаемая строка \n"<<v;
cin.getline(str3,n,'\n');
delete [] str1;
delete [] str2;
delete [] str3;
delete [] v;
break;}
case '2':
{cout<<"Введите предложение и нажмите Enter \n";
cin.ignore(n,'\n');
cin.getline(pre,n,'\n');
if(zapyataya1(pre,x)==0)cout<<pre<<endl;
if(zapyataya1(pre,x)!=0&&zapyataya1(pre,x)==zapyataya2(pre,x))
{for(int i=zapyataya1(pre,x)+1;i<len(pre);i++){cout<<pre[i];}cout<<endl;};
if(zapyataya1(pre,x)!=0&&zapyataya1(pre,x)!=zapyataya2(pre,x))
{for(int i=zapyataya1(pre,x)+1;i<zapyataya2(pre,x);i++){cout<<pre[i];}cout<<endl;}
break;}
case '3':
{cout<<"Введите предложение и нажмите Enter \n";
cin.ignore(n,'\n');
cin.getline(za31,n,'\n');
cout<<"Введите что менять и нажмите Enter \n";
cin.getline(za32,n,'\n');
cout<<"Введите на что менять и нажмите Enter \n";
cin.getline(za33,n,'\n');
strreplace(za31,za32,za33);
cout<<"Новая строка: "<<za31<<endl;
break;}
default:cout<<"Либо вы ввели не число, либо такой задачи нет!"<<endl;
break;}
cin.ignore(n,'\n');
cout<<"Хотите выйти? (введите д/Д или н/Н)\n";
cin>>c;
}
while(c=='n'||c=='н'||c=='Н');
return 0;
}
//--------------------------------------------------------------------------- |