-
Notifications
You must be signed in to change notification settings - Fork 0
/
for_partition.cpp
233 lines (219 loc) · 5.3 KB
/
for_partition.cpp
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "header.h"
using namespace std;
int token[1000];
int p=0;
bool an_alphabet(char s)
{
if((s >= 'a' && s <= 'z') || (s >= 'A' && s <= 'Z'))
return true;
else
return false;
}
bool a_digit(char s)
{
if(s >= '0' && s <= '9')
return true;
else
return false;
}
bool an_operator(char s)
{
if(s=='+' || s== '-' || s== '*' || s=='/' )
return true;
else
return false;
}
bool a_power(char s)
{
if(s== '^' )
return true;
else
return false;
}
bool a_bracket(char s)
{
if(s == '(' || s == ')' || s == '[' || s == ']' || s == '{' || s =='}')
return true;
else
return false;
}
void all_partition()
{
p++;
}
void partition_null()
{
p=0;
}
int for_know_type(string equ)
{
int xk=0,as_we_k=0;
char sk='\0';
for(int i=0;i<equ.size();i++)
{
xk=char_type(equ[i]);
if(xk==3)
{
if(equ[i-1]=='(')
continue;
else if(equ[i]=='*')
continue;
else if(equ[i-1]!='^')
sk = equ[i];
else
continue;
}
if(sk=='+' || sk == '-' || equ[i]==')')
as_we_k++;
sk='\0';
}
return as_we_k;
}
void uplusv(string equ, char caa)
{
int x13=0;
char s13='\0';
string temp_equ = "";
for(int i=0; i<equ.size(); i++)
{
x13 = char_type(equ[i]);
if(x13==3)
{
if(equ[i-1]=='(')
continue;
else if(equ[i]=='*')
{
temp_equ += equ[i];
continue;
}
else if(equ[i-1]!='^')
s13 = equ[i];
else {
temp_equ += equ[i];
continue;
}
}
if(equ[i]=='(')
continue;
if(s13=='\0')
temp_equ += equ[i];
if(s13=='+' || s13=='-' || equ[i]==')')
{
cout<<"d/d"<<caa<<"(";
if(equ[i]==')')
cout<<temp_equ;
else
cout<<temp_equ<<") "<<s13<<" ";
temp_equ = "";
}
s13 = '\0';
}
cout<<"\n\n\t\t\t = ";
}
string Partition(string equ,int size)
{
char variable;
int pow=1,coeffi=1;
char sign='\0';
string ans2="";
for(int i=0; i<size; i++)
{
if(token[i]==1)
{
variable = equ[i];
if(token[i+1] != 4)
pow=1;
if(equ[i-1] == '+')
coeffi=1;
else if(equ[i-1] == '-')
coeffi=-1;
}
else if(token[i]==2)
{
if(equ[i+1] == '*' )
coeffi = (int)(equ[i])-48;
if(equ[i-1]=='-' && equ[i-2]=='(')
{
coeffi=coeffi*(-1);
}
if( (equ[i-2] != '^' ) && (equ[i-1]=='+' || equ[i-1]=='-' ) && (equ[i+1]=='+' || equ[i+1]=='-' ) )
coeffi=1321;
else if( (equ [i-2] !='^' ) && (equ[i-1]=='+' || equ[i-1]=='-' ) && ( equ[i+1]=='(' || equ[i+1] ==')' ))
{
coeffi = 1322;
variable = equ[i];
}
else if((equ[i-1]=='(' || equ[i-1]==')' ) && ( equ [i+1]=='+' || equ[i+1]== '-' ) )
{
coeffi = 1323;
variable = equ[i];
}
else if((equ[i-1]=='(' || equ[i-1]==')') && (equ[i+1]=='(' || equ[i+1]==')'))
{
coeffi = 1324;
variable = equ[i];
}
}
else if(token[i]==3)
{
if(equ[i] == '*')
continue;
else if(equ[i-1] == '(')
continue;
else if(equ[i-1] != '^')
sign = equ[i];
else
continue;
}
else if(token[i]==4)
{
if(token [i+1] ==2)
pow = (int)(equ[i+1])-48;
else if(equ[i+1]== '-' )
{
pow = (int)(equ[i+2])-48;
pow = -pow ;
}
}
if(sign=='+' || sign=='-' || equ[i]==')')
{
ans2 +=derivative(variable,pow,coeffi,sign);
if(p>0 && coeffi != 1323)
cout<<")";
sign='\0';
coeffi = 1;
pow = 1;
}
}
coeffi=0;
pow=0;
variable='\0';
sign='\0';
null_universe();
ans2+=")";
if(p>0)
cout<<"\n\n\t\t\t = ";
return ans2;
}
string for_partition(string equ)
{
int size=0;
for (int i = 0; equ[i] ; i++)
size++;
for(int i=0; i<size; i++)
{
if(an_alphabet(equ[i]))
token[i] = 1;
else if(a_digit(equ[i]))
token[i] = 2;
else if(an_operator(equ[i]))
token[i] = 3;
else if(a_power(equ[i]))
token[i] = 4;
else if(a_bracket(equ[i]))
token[i] = 5;
}
string ans1 = "";
ans1 += Partition(equ,size);
return ans1;
}