From aecc04d003d4fac10ae4063691026b3baec494ac Mon Sep 17 00:00:00 2001 From: Arno <15528622+arno-1@user.noreply.gitee.com> Date: Sat, 27 Sep 2025 14:45:50 +0800 Subject: [PATCH] Initial commit --- doc/README.md | 4 ++-- src/Generator/G_ques.java | 1 + src/Generator/Jun_g_ques.java | 21 ++++++++++++++++++++- src/Generator/Pri_g_ques.java | 5 +++++ src/Generator/Sen_g_ques.java | 20 +++++++++++++++++++- src/META-INF/MANIFEST.MF | 3 +++ 6 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/META-INF/MANIFEST.MF diff --git a/doc/README.md b/doc/README.md index fe253d4..4d798d1 100644 --- a/doc/README.md +++ b/doc/README.md @@ -28,8 +28,8 @@ ## 题目生成说明 1. 小学题目2-5个操作数,运算包含+、-、*、\,随机加括号 -2. 初中题目1-5个操作数,运算包含+、-、*、\,随机加平方或开根(至少一个),没有括号 -3. 高中题目1-5个操作数,运算包含+、-、*、\,每一项均为三角函数,随机加平方。 +2. 初中题目1-5个操作数,运算包含+、-、*、\,随机加平方或开根(至少一个),随机加括号 +3. 高中题目1-5个操作数,运算包含+、-、*、\,每一项均为三角函数,随机加平方,随机加括号。 --- 软件2302 202326010228 乔毅凡 \ No newline at end of file diff --git a/src/Generator/G_ques.java b/src/Generator/G_ques.java index c3017cb..5a18448 100644 --- a/src/Generator/G_ques.java +++ b/src/Generator/G_ques.java @@ -4,4 +4,5 @@ public interface G_ques { String g_question(); String g_type(); char g_operator(); + String add_brackets(StringBuilder s,int count); } diff --git a/src/Generator/Jun_g_ques.java b/src/Generator/Jun_g_ques.java index 8a8585a..4eb84df 100644 --- a/src/Generator/Jun_g_ques.java +++ b/src/Generator/Jun_g_ques.java @@ -47,7 +47,7 @@ public class Jun_g_ques implements G_ques{ question = new StringBuilder(String.join(" ", parts)); } } - return question.toString(); + return add_brackets(question,count); } @Override @@ -60,4 +60,23 @@ public class Jun_g_ques implements G_ques{ char[] op={'+','-','*','/'}; return op[ra.nextInt(op.length)]; } + + @Override + public String add_brackets(StringBuilder s,int count){ + String res=s.toString(); + String[] parts=s.toString().split(" "); + if (ra.nextBoolean()&&parts.length!=1) { + int num=ra.nextInt(3)+1; + for (int i=0;i