课堂测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | #include <iostream> #include <random> #include <time.h> using namespace std; double f1( double a) { return a / 30; } int main() { clock_t start, finish; // 挂钟时间 double t = 0; int f = 0; random_device rd; // 用于获得随机种子 mt19937 gen1(rd()); // 以随机种子初始化随机数生成器 mt19937 gen2(rd()); mt19937 gen3(rd()); uniform_int_distribution< int > dist1(10, 99); // 生成 [10, 99] 范围内的整数 uniform_int_distribution< int > dist2(1, 4); // 生成 [1, 4] 范围内的整数 uniform_real_distribution< double > dist3(10.0000000, 99.00000000); uniform_real_distribution< double > dist4(1.0000000, 4.000000); int a[30] = { 0 }; for ( int i = 0; i < 30; i++) { int randomNum1, randomNum2, randomNum3, n; do { randomNum1 = dist1(gen1); // 生成随机数 randomNum2 = dist1(gen2); randomNum3 = dist2(gen3); } while (randomNum1 == randomNum2); double GameTime = 1000; // 游戏时间 double gametime; // 用户所用时间 if (randomNum3 == 1) { n = randomNum1 + randomNum2; cout << i + 1 << " " << randomNum1; cout << "+" ; cout << randomNum2 << "=" << endl; } if (randomNum3 == 2) { n = randomNum1 - randomNum2; if (n < 0) { cout << i + 1 << " " << randomNum2; cout << "-" ; cout << randomNum1 << "=" << endl; n = randomNum2 - randomNum1; } else { cout << i + 1 << " " << randomNum1; cout << "-" ; cout << randomNum2 << "=" << endl; n = randomNum1 - randomNum2; } } if (randomNum3 == 3) { n = randomNum1 * randomNum2; while (n >= 1000) { n = randomNum1 * randomNum2; randomNum1--; randomNum2--; } n = randomNum1 * randomNum2; cout << i + 1 << " " << randomNum1; cout << "*" ; cout << randomNum2 << "=" << endl; } if (randomNum3 == 4) { do { randomNum1 = dist3(gen1); // 生成随机数 randomNum2 = dist4(gen2); } while (randomNum1 % randomNum2 != 0 && randomNum1 < randomNum2 && randomNum1 != 0 && randomNum2 != 0); n = randomNum1 / randomNum2; cout << i + 1 << " " << randomNum1 << "/" << randomNum2 << "=" << endl; } start = clock (); cin >> a[i]; finish = clock (); gametime = ( double )(finish - start) / CLOCKS_PER_SEC; if (gametime >= GameTime) { cout << "很遗憾,未能在规定时间内得出答案 正确结果" << n << endl; f++; continue ; } if (a[i] == n) { cout << "true" << endl; t++; } else { cout << "false 正确结果 " << n << endl; f++; } } cout << "错题数:" << f << endl; cout << "正确率:" << f1(t) << endl; return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | import java.util.Random; import java.util.Scanner; public class Main { public static double f1( double a) { return a / 30 ; } public static void main(String[] args) { long start, finish; // 挂钟时间 double t = 0 ; int f = 0 ; Random rd = new Random(); // 用于获得随机种子 int [] a = new int [ 30 ]; for ( int i = 0 ; i < 30 ; i++) { int randomNum1, randomNum2, randomNum3, n; do { randomNum1 = rd.nextInt( 90 ) + 10 ; // 生成随机数 randomNum2 = rd.nextInt( 90 ) + 10 ; randomNum3 = rd.nextInt( 4 ) + 1 ; } while (randomNum1 == randomNum2); double GameTime = 1000 ; // 游戏时间 double gametime; // 用户所用时间 if (randomNum3 == 1 ) { n = randomNum1 + randomNum2; System.out.print((i + 1 ) + " " + randomNum1); System.out.print( "+" ); System.out.println(randomNum2 + "=" ); } if (randomNum3 == 2 ) { n = randomNum1 - randomNum2; if (n < 0 ) { System.out.print((i + 1 ) + " " + randomNum2); System.out.print( "-" ); System.out.println(randomNum1 + "=" ); n = randomNum2 - randomNum1; } else { System.out.print((i + 1 ) + " " + randomNum1); System.out.print( "-" ); System.out.println(randomNum2 + "=" ); n = randomNum1 - randomNum2; } } if (randomNum3 == 3 ) { n = randomNum1 * randomNum2; while (n >= 1000 ) { n = randomNum1 * randomNum2; randomNum1--; randomNum2--; } n = randomNum1 * randomNum2; System.out.print((i + 1 ) + " " + randomNum1); System.out.print( "*" ); System.out.println(randomNum2 + "=" ); } if (randomNum3 == 4 ) { do { randomNum1 = rd.nextInt( 90 ) + 10 ; // 生成随机数 randomNum2 = rd.nextInt( 3 ) + 1 ; } while (randomNum1 % randomNum2 != 0 && randomNum1 < randomNum2 && randomNum1 != 0 && randomNum2 != 0 ); n = randomNum1 / randomNum2; System.out.println((i + 1 ) + " " + randomNum1 + "/" + randomNum2 + "=" ); } start = System.nanoTime(); Scanner scanner = new Scanner(System.in); a[i] = scanner.nextInt(); finish = System.nanoTime(); gametime = ( double ) (finish - start) / 1_000_000_000; if (gametime >= GameTime) { System.out.println( "很遗憾,未能在规定时间内得出答案 正确结果 " + n); f++; continue ; } if (a[i] == n) { System.out.println( "true" ); t++; } else { System.out.println( "false 正确结果 " + n); f++; } } System.out.println( "错题数:" + f); System.out.println( "正确率:" + f1(t)); } } |
课堂上写的C++,回来改成java了。
因为就生成30个随机题目,不需要保证题目不重复。因为可能性太低了,如果一定要,会浪费大量时间,所以我在此删去了这段代码
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix