54{
55
56 std::deque<std::string> e_3;
57 std::deque<std::string> e_4;
58
59 std::deque<std::string> e_3_comb;
60 std::deque<std::string> e_4_comb;
61
62 std::deque<std::string> e_43_comb;
63 std::deque<std::string> e_34_comb;
64
65 std::deque<std::string> e_434_comb;
66 std::deque<std::string> e_343_comb;
67
68 {
69 std::deque<std::string> operator_list;
71
72 std::string expr[] =
73 {
74 "((xAy)Bz)",
75 "(xA(yBz))",
76 "((3.579Ay)Bz)",
77 "(3.579A(yBz))",
78 "((xA5.793)Bz)",
79 "(xA(5.793Bz))",
80 "((xAy)B7.935)",
81 "(xA(yB7.935))",
82 "((3.579A5.793)Bz)",
83 "(3.579A(5.793Bz))",
84 "((3.579Ay)B7.935)",
85 "(3.579A(yB7.935))",
86 "((xA5.793)B7.935)",
87 "(xA(5.793B7.935))",
88 "((3.579A5.793)B7.935)",
89 "(3.579A(5.793B7.935))"
90 };
91
92 for (std::size_t i = 0; i < sizeof(expr) / sizeof(std::string); ++i)
93 {
94 std::size_t loc[] =
95 {
96 expr[i].find("A"),
97 expr[i].find("B")
98 };
99
100 for (std::size_t j = 0; j < operator_list.size(); ++j)
101 {
102 std::string curr_expr = expr[i];
103 for (std::size_t k = 0; k < sizeof(loc)/sizeof(std::size_t); ++k)
104 {
105 curr_expr[loc[k]] = operator_list[j][k];
106 }
107
108
109 e_3.push_back(curr_expr);
110 }
111 }
112 }
113
114 {
115 std::deque<std::string> operator_list;
117
118 std::string expr[] =
119 {
120 "((xAy)B(zCw))",
121 "((xA(yB(zCw))))",
122 "((xA((yBz)Cw)))",
123 "((((xAy)Bz)Cw))",
124 "(((xA(yBz))Cw))",
125 "((3.579Ay)B(zCw))",
126 "((3.579A(yB(zCw))))",
127 "((3.579A((yBz)Cw)))",
128 "((((3.579Ay)Bz)Cw))",
129 "(((3.579A(yBz))Cw))",
130 "((xA5.793)B(zCw))",
131 "((xA(5.793B(zCw))))",
132 "((xA((5.793Bz)Cw)))",
133 "((((xA5.793)Bz)Cw))",
134 "(((xA(5.793Bz))Cw))",
135 "((xAy)B(7.935Cw))",
136 "((xA(yB(7.935Cw))))",
137 "((xA((yB7.935)Cw)))",
138 "((((xAy)B7.935)Cw))",
139 "(((xA(yB7.935))Cw))",
140 "((xAy)B(zC9.357))",
141 "((xA(yB(zC9.357))))",
142 "((xA((yBz)C9.357)))",
143 "((((xAy)Bz)C9.357))",
144 "(((xA(yBz))C9.357))",
145 "((3.579A5.793)B(zCw))",
146 "((3.579A(5.793B(zCw))))",
147 "((3.579A((5.793Bz)Cw)))",
148 "((((3.579A5.793)Bz)Cw))",
149 "(((3.579A(5.793Bz))Cw))",
150 "((3.579Ay)B(5.793Cw))",
151 "((3.579A(yB(5.793Cw))))",
152 "((3.579A((yB5.793)Cw)))",
153 "((((3.579Ay)B5.793)Cw))",
154 "(((3.579A(yB5.793))Cw))",
155 "((3.579Ay)B(zC9.357))",
156 "((3.579A(yB(zC9.357))))",
157 "((3.579A((yBz)C9.357)))",
158 "((((3.579Ay)Bz)C9.357))",
159 "(((3.579A(yBz))C9.357))",
160 "((xA5.793)B(7.935Cw))",
161 "((xA(5.793B(7.935Cw))))",
162 "((xA((5.793B7.935)Cw)))",
163 "((((xA5.793)B7.935)Cw))",
164 "(((xA(5.793B7.935))Cw))",
165 "((xA5.793)B(zC9.357))",
166 "((xA(5.793B(zC9.357))))",
167 "((xA((5.793Bz)C9.357)))",
168 "((((xA5.793)Bz)C9.357))",
169 "(((xA(5.793Bz))C9.357))",
170 "((xAy)B(7.935C9.357))",
171 "((xA(yB(7.935C9.357))))",
172 "((xA((yB7.935)C9.357)))",
173 "((((xAy)B7.935)C9.357))",
174 "(((xA(yB7.935))C9.357))",
175 "((3.579A5.793)B(7.935C9.357))",
176 "((3.579A(5.793B(7.935C9.357))))",
177 "((3.579A((5.793B7.935)C9.357)))",
178 "((((3.579A5.793)B7.935)C9.357))",
179 "(((3.579A(5.793B7.935))C9.357))"
180 };
181
182 for (std::size_t i = 0; i < sizeof(expr) / sizeof(std::string); ++i)
183 {
184 std::size_t loc[] =
185 {
186 expr[i].find("A"),
187 expr[i].find("B"),
188 expr[i].find("C")
189 };
190
191 for (std::size_t j = 0; j < operator_list.size(); ++j)
192 {
193 std::string curr_expr = expr[i];
194 for (std::size_t k = 0; k < sizeof(loc)/sizeof(std::size_t); ++k)
195 {
196 curr_expr[loc[k]] = operator_list[j][k];
197 }
198
199
200 e_4.push_back(curr_expr);
201 }
202 }
203 }
204
205 {
206 const std::string operators = "+-*/";
207 std::size_t opr_index = 0;
208 for (std::size_t i = 0; i < e_3.size(); ++i)
209 {
210 std::string curr_str = "(" + e_3[i] + operators[opr_index] + e_3[(i + 10) % e_3.size()] + ")";
211 e_3_comb.push_back(curr_str);
212 opr_index = (opr_index + 1) % operators.size();
213 }
214 }
215
216 {
217 const std::string operators = "+-*/";
218 std::size_t opr_index = 0;
219 for (std::size_t i = 0; i < e_4.size(); ++i)
220 {
221 std::string curr_str = "(" + e_4[i] + operators[opr_index] + e_4[(i + 10) % e_4.size()] + ")";
222 e_4_comb.push_back(curr_str);
223 opr_index = (opr_index + 1) % operators.size();
224 }
225 }
226
227 {
228 const std::string operators = "+-*/";
229 std::size_t opr_index = 0;
230 for (std::size_t i = 0; i < e_4.size(); ++i)
231 {
232 std::string curr_str = "(" + e_4[i] + operators[opr_index] + e_3[i % e_3.size()] + ")";
233 e_43_comb.push_back(curr_str);
234 opr_index = (opr_index + 1) % operators.size();
235 }
236 }
237
238 {
239 const std::string operators = "+-*/";
240 std::size_t opr_index = 0;
241 for (std::size_t i = 0; i < e_4.size(); ++i)
242 {
243 std::string curr_str = "(" + e_3[i % e_3.size()] + operators[opr_index] + e_4[i] + ")";
244 e_34_comb.push_back(curr_str);
245 opr_index = (opr_index + 1) % operators.size();
246 }
247 }
248
249 {
250 const std::string operators = "+-*/";
251 std::size_t opr_index = 0;
252 for (std::size_t i = 0; i < e_4.size(); ++i)
253 {
254 std::size_t opr_index0 = opr_index;
255 std::size_t opr_index1 = opr_index = (opr_index + 1) % operators.size();
256 opr_index = (opr_index + 1) % operators.size();
257 std::string curr_str = "(" + e_4[i] + operators[opr_index0] + e_3[i % e_3.size()] + operators[opr_index1] + e_4[(i + 3) % e_4.size()] + ")";
258 e_434_comb.push_back(curr_str);
259 }
260 }
261
262 {
263 const std::string operators = "+-*/";
264 std::size_t opr_index = 0;
265 for (std::size_t i = 0; i < e_4.size(); ++i)
266 {
267 std::size_t opr_index0 = opr_index;
268 std::size_t opr_index1 = opr_index = (opr_index + 1) % operators.size();
269 opr_index = (opr_index + 1) % operators.size();
270 std::string curr_str = "(" + e_3[i % e_3.size()] + operators[opr_index0] + e_4[i] + operators[opr_index1] + e_3[(i + 3) % e_3.size()] + ")";
271 e_343_comb.push_back(curr_str);
272 }
273 }
274
275 std::copy(e_3.begin(),e_3.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
276 std::copy(e_4.begin(),e_4.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
277
278 std::copy(e_3_comb.begin(),e_3_comb.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
279 std::copy(e_4_comb.begin(),e_4_comb.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
280
281 std::copy(e_43_comb.begin(),e_43_comb.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
282 std::copy(e_34_comb.begin(),e_34_comb.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
283
284
285 std::copy(e_434_comb.begin(),e_434_comb.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
286 std::copy(e_343_comb.begin(),e_343_comb.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
287
288 return 0;
289}