From 42556dbdecfe59dcb9351e5012b2bc52bab9e4f7 Mon Sep 17 00:00:00 2001
From: pve6agnmp <3032679629@qq.com>
Date: Mon, 29 Sep 2025 17:05:24 +0800
Subject: [PATCH 1/2] Initial commit
---
README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 README.md
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b1a8c84
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+# personal
+
--
2.34.1
From 1ef0fecba83e24f0b07c3f881096a45fceb6574b Mon Sep 17 00:00:00 2001
From: 30326 <3032679629@qq.com>
Date: Mon, 29 Sep 2025 21:57:07 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E8=BD=AF=E4=BB=B61=E7=8F=AD=20202218110221?=
=?UTF-8?q?=20=E6=9D=8E=E6=B6=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 30 ++++
.idea/.gitignore | 8 ++
.idea/misc.xml | 6 +
.idea/modules.xml | 8 ++
.idea/vcs.xml | 6 +
develop.iml | 11 ++
src/MathTestGenerator.java | 275 +++++++++++++++++++++++++++++++++++++
7 files changed, 344 insertions(+)
create mode 100644 .gitignore
create mode 100644 .idea/.gitignore
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 develop.iml
create mode 100644 src/MathTestGenerator.java
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..13275f1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,30 @@
+### IntelliJ IDEA ###
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+.kotlin
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..188022c
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..32c6fae
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/develop.iml b/develop.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/develop.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/MathTestGenerator.java b/src/MathTestGenerator.java
new file mode 100644
index 0000000..4fede5c
--- /dev/null
+++ b/src/MathTestGenerator.java
@@ -0,0 +1,275 @@
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+class Question {
+ private String content;
+ private String answer;
+
+ public Question(String content, String answer) {
+ this.content = content;
+ this.answer = answer;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public String getAnswer() {
+ return answer;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Question question = (Question) o;
+ return content.equals(question.content);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(content);
+ }
+}
+
+class User {
+ private String username;
+ private String password;
+ private String level; // 小学、初中、高中
+
+ public User(String username, String password, String level) {
+ this.username = username;
+ this.password = password;
+ this.level = level;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getLevel() {
+ return level;
+ }
+
+ public void setLevel(String level) {
+ this.level = level;
+ }
+}
+
+public class MathTestGenerator {
+ private static List users = new ArrayList<>();
+ private static User currentUser = null;
+ private static final String BASE_DIR = "math_questions/";
+
+ static {
+ users.add(new User("张三1", "123", "小学"));
+ users.add(new User("张三2", "123", "小学"));
+ users.add(new User("张三3", "123", "小学"));
+
+ users.add(new User("李四1", "123", "初中"));
+ users.add(new User("李四2", "123", "初中"));
+ users.add(new User("李四3", "123", "初中"));
+
+ users.add(new User("王五1", "123", "高中"));
+ users.add(new User("王五2", "123", "高中"));
+ users.add(new User("王五3", "123", "高中"));
+
+ new File(BASE_DIR).mkdirs();
+ }
+
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+
+ while (true) {
+ if (currentUser == null) {
+ System.out.print("请输入用户名和密码(用空格隔开):");
+ String input = scanner.nextLine().trim();
+ String[] parts = input.split(" ");
+
+ if (parts.length != 2) {
+ System.out.println("请输入正确的用户名、密码");
+ continue;
+ }
+
+ User user = authenticate(parts[0], parts[1]);
+ if (user != null) {
+ currentUser = user;
+ System.out.println("当前选择为 " + currentUser.getLevel() + " 出题");
+ } else {
+ System.out.println("请输入正确的用户名、密码");
+ }
+ } else {
+ System.out.print("准备生成 " + currentUser.getLevel() + " 数学题目,请输入生成题目数量(输入-1将退出当前用户,重新登录):");
+ String input = scanner.nextLine().trim();
+
+ if (input.startsWith("切换为")) {
+ String level = input.substring(3).trim();
+ if (level.equals("小学") || level.equals("初中") || level.equals("高中")) {
+ currentUser.setLevel(level);
+ System.out.println("系统提示:准备生成 " + currentUser.getLevel() + " 数学题目,请输入生成题目数量");
+ } else {
+ System.out.println("请输入小学、初中和高中三个选项中的一个");
+ }
+ continue;
+ }
+
+ try {
+ int count = Integer.parseInt(input);
+ if (count == -1) {
+ currentUser = null;
+ System.out.println("已退出当前用户");
+ } else if (count >= 10 && count <= 30) {
+ generateQuestions(count);
+ } else {
+ System.out.println("题目数量必须在10-30之间,请重新输入");
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("请输入有效的数字");
+ }
+ }
+ }
+ }
+
+ private static User authenticate(String username, String password) {
+ for (User user : users) {
+ if (user.getUsername().equals(username) && user.getPassword().equals(password)) {
+ return user;
+ }
+ }
+ return null;
+ }
+
+ private static void generateQuestions(int count) {
+ String level = currentUser.getLevel();
+ Set allQuestions = new HashSet<>();
+ Set existingQuestions = loadExistingQuestions();
+
+ while (allQuestions.size() < count) {
+ Question question = generateQuestion(level);
+ if (!existingQuestions.contains(question) && !allQuestions.contains(question)) {
+ allQuestions.add(question);
+ }
+ }
+
+ saveQuestions(allQuestions);
+ System.out.println("已生成" + count + "道" + level + "数学题目,并保存到文件");
+ }
+
+ private static Question generateQuestion(String level) {
+ Random random = new Random();
+ int operandCount = random.nextInt(5) + 1; // 1-5个操作数
+ List operands = new ArrayList<>();
+
+ for (int i = 0; i < operandCount; i++) {
+ operands.add(random.nextInt(100) + 1); // 1-100的数字
+ }
+
+ List operators = new ArrayList<>();
+ if (level.equals("小学")) {
+ char[] ops = {'+', '-', '*', '/'};
+ for (int i = 0; i < operandCount - 1; i++) {
+ operators.add(ops[random.nextInt(4)]);
+ }
+ } else if (level.equals("初中")) {
+ char[] ops = {'+', '-', '*', '/', '^'};
+ for (int i = 0; i < operandCount - 1; i++) {
+ operators.add(ops[random.nextInt(5)]);
+ }
+ } else {
+ char[] ops = {'+', '-', '*', '/', '^', 's', 'c', 'l'}; // s:sin, c:cos, l:log
+ for (int i = 0; i < operandCount - 1; i++) {
+ operators.add(ops[random.nextInt(8)]);
+ }
+ }
+
+ StringBuilder questionStr = new StringBuilder();
+ questionStr.append(operands.get(0));
+
+ for (int i = 0; i < operators.size(); i++) {
+ char op = operators.get(i);
+ switch (op) {
+ case '^':
+ questionStr.append("^").append(operands.get(i + 1));
+ break;
+ case 's':
+ questionStr.append("+sin(").append(operands.get(i + 1)).append(")");
+ break;
+ case 'c':
+ questionStr.append("+cos(").append(operands.get(i + 1)).append(")");
+ break;
+ case 'l':
+ questionStr.append("+log(").append(operands.get(i + 1)).append(")");
+ break;
+ default:
+ questionStr.append(op).append(operands.get(i + 1));
+ }
+ }
+ questionStr.append(" = ?");
+
+ String answer = calculateAnswer(operands, operators, level);
+
+ return new Question(questionStr.toString(), answer);
+ }
+
+ private static String calculateAnswer(List operands, List operators, String level) {
+ return "计算结果";
+ }
+
+ private static Set loadExistingQuestions() {
+ Set questions = new HashSet<>();
+ String userDir = BASE_DIR + currentUser.getUsername() + "/";
+ File dir = new File(userDir);
+
+ if (!dir.exists()) {
+ return questions;
+ }
+
+ File[] files = dir.listFiles((d, name) -> name.endsWith(".txt"));
+ if (files == null) {
+ return questions;
+ }
+
+ for (File file : files) {
+ try (BufferedReader br = new BufferedReader(new FileReader(file))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ line = line.trim();
+ if (line.matches("\\d+\\. .+ = \\?")) {
+ String content = line.substring(line.indexOf(". ") + 2);
+ questions.add(new Question(content, ""));
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return questions;
+ }
+
+ private static void saveQuestions(Set questions) {
+ String userDir = BASE_DIR + currentUser.getUsername() + "/";
+ new File(userDir).mkdirs();
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
+ String fileName = userDir + sdf.format(new Date()) + ".txt";
+
+ try (BufferedWriter bw = new BufferedWriter(new FileWriter(fileName))) {
+ List questionList = new ArrayList<>(questions);
+ for (int i = 0; i < questionList.size(); i++) {
+ bw.write((i + 1) + ". " + questionList.get(i).getContent());
+ bw.newLine();
+ if (i != questionList.size() - 1) {
+ bw.newLine();
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
--
2.34.1