ADD file via upload

hnu202326010302 6 days ago
parent 0ced5eae93
commit c9026aace3

@ -0,0 +1,124 @@
import java.util.Random;
import java.util.Scanner;
public class Highproblem implements Makeproblem{
private static Random random = new Random();
static int basic=1;
String name="1";
String time="1";
int num=1;
public static void main(String[] args) {
for (int i = 0; i < 15; i++) {
basic=1;
Highproblem h1 = new Highproblem();
System.out.println((i + 1) + ". " + h1.generateSmartExpression());
}
}
void start(int num,String username){
name=username;
Timemanage t1=new Timemanage();
time=t1.timeget();
for (int i = 0; i < num; i++) {
basic=1;
System.out.println((i + 1) + ". " + generateSmartExpression());
System.out.println("");
}
}
@Override
public String generateSmartExpression() {
int operatorCount = random.nextInt(3) + 1;
int b2=random.nextInt(operatorCount) + 1;
String file=time;
String result;
while(true){
int flag=0;
result=buildExpression(operatorCount,b2);
filemanage f1=new filemanage();
f1.fileread(name);
f1.fileread(name);
for(String i:f1.array){
String[] parts = i.split("\\.", 2);
String j = parts.length > 1 ? parts[1] : i;
if(result.equals(j)){
flag=1;
}
}
if(flag==1){
continue;
}
f1.filecreate(name,file);
f1.filewrite(name,file,num+"."+result);
f1.filewrite(name,file," ");
num++;
break;
}
return result;
}
@Override
public String buildExpression(int operatorCount,int b2) {
if (operatorCount == 1) {
return generateSimpleExpression(b2);
}
// 随机决定分割点来添加括号
int splitPoint = random.nextInt(operatorCount - 1) + 1;
String leftPart = (splitPoint > 1 && random.nextBoolean()) ?
"(" + buildExpression(splitPoint,b2) + ")" :
buildExpression(splitPoint,b2);
String rightPart = (operatorCount - splitPoint > 1 && random.nextBoolean()) ?
"(" + buildExpression(operatorCount - splitPoint,b2) + ")" :
buildExpression(operatorCount - splitPoint,b2);
char operator = getRandomOperator("+-*/");
return leftPart + " " + operator + " " + rightPart;
}
@Override
public String generateSimpleExpression(int b2) {
int a = random.nextInt(100) + 1;
int b = random.nextInt(100) + 1;
char op = getRandomOperator("+-*/√²123");
if(basic==b2){
op = getRandomOperator("123");
if(op=='1'){
basic=0;
return "sin"+b+"°";
}else if(op=='2'){
basic=0;
return "cos"+b+"°";
}else if(op=='3'){
basic=0;
return "tan"+b+"°";
}
}else {
basic++;
}
if(random.nextInt(2)==0){
return a+"";
}
if(op=='√'){
return op +""+b;
}else if(op=='1'){
return "sin"+b+"°";
}else if(op=='2'){
return "cos"+b+"°";
}else if(op=='3'){
return "tan"+b+"°";
}
else if(op=='²'){
return a+""+ op ;
}else{
if(random.nextBoolean()){
return a + " " + op + " " + b;
}else
{
return "("+a + " " + op + " " + b+")";
}
}
}
@Override
public char getRandomOperator(String operators) {
return operators.charAt(random.nextInt(operators.length()));
}
}
Loading…
Cancel
Save