|
|
|
@ -17,18 +17,13 @@ public class JuniorProblem implements ProblemsGenerator {
|
|
|
|
|
do {
|
|
|
|
|
int numCount = RANDOM.nextInt(5) + 1;
|
|
|
|
|
expression = expressionBuilder.generateBasicExpression(numCount);
|
|
|
|
|
List<Integer> numPositions = expressionBuilder.getNumberPositions(expression);
|
|
|
|
|
|
|
|
|
|
if (RANDOM.nextDouble() < 0.8) {
|
|
|
|
|
int pairs = bracketManager.decideParenthesesPairs(numCount);
|
|
|
|
|
if (pairs > 0) {
|
|
|
|
|
expression = bracketManager.addParentheses(expression, pairs, numPositions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
expression = bracketManager.addNestedParentheses(expression);
|
|
|
|
|
|
|
|
|
|
// 添加幂运算并检查添加是否成功
|
|
|
|
|
expression = powerManager.addPowerOperations(expression, numPositions);
|
|
|
|
|
List<Integer> numPositions = expressionBuilder.getNumberPositions(expression);
|
|
|
|
|
expression = powerManager.addPowerOperations(expression, numPositions, null);
|
|
|
|
|
hasPower = expression.contains("^2") || expression.contains("√");
|
|
|
|
|
|
|
|
|
|
} while (expressionBuilder.hasDivideByZero(expression) || !hasPower);
|
|
|
|
|
|
|
|
|
|
return expression;
|
|
|
|
|