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
| #include <stdio.h> #include <stdlib.h> #include <time.h>
#define TOTAL_SINGLE 40 #define TOTAL_MULTIPLE 20 #define TOTAL_TRUE_FALSE 20 #define MAX_CHAPTERS 8
const int singleCounts[MAX_CHAPTERS] = {26, 188, 117, 117, 145, 32, 45, 22}; const int multipleCounts[MAX_CHAPTERS] = {26, 106, 119, 116, 87, 76, 59, 27}; const int trueFalseCounts[MAX_CHAPTERS] = {18, 114, 77, 54, 43, 50, 37, 49};
int score = 0;
void generateQuestion(int type, int chapter, int question, int currentIndex) { const char *typeStr; if (type == 1) typeStr = "dan"; else if (type == 2) typeStr = "duo"; else typeStr = "pan";
printf("试卷第%d题: %d.%s.%d ", currentIndex, chapter, typeStr, question); }
int getRandomQuestion(int totalQuestions) { return rand() % totalQuestions + 1; }
int main() { srand(time(NULL));
int usedSingle = 0, usedMultiple = 0, usedTrueFalse = 0; int selectedChapters[MAX_CHAPTERS] = {0};
printf("随机试卷生成开始
");
int currentIndex = 1;
for (int i = 0; i < TOTAL_SINGLE; i++, currentIndex++) { int chapter = rand() % MAX_CHAPTERS; int question = getRandomQuestion(singleCounts[chapter]); generateQuestion(1, chapter, question, currentIndex);
printf("请输入答案是否正确(1错误/2正确,3提前交卷): "); int isCorrect; scanf("%d", &isCorrect);
if (isCorrect == 3) { printf("提前交卷,未作答的题目将按错误处理。 "); goto finish; }
if (isCorrect == 2) score += 1; }
for (int i = 0; i < TOTAL_MULTIPLE; i++, currentIndex++) { int chapter = rand() % MAX_CHAPTERS; int question = getRandomQuestion(multipleCounts[chapter]); generateQuestion(2, chapter, question, currentIndex);
printf("请输入答案是否正确(1错误/2正确,3提前交卷): "); int isCorrect; scanf("%d", &isCorrect);
if (isCorrect == 3) { printf("提前交卷,未作答的题目将按错误处理。 "); goto finish; }
if (isCorrect == 2) score += 2; }
for (int i = 0; i < TOTAL_TRUE_FALSE; i++, currentIndex++) { int chapter = rand() % MAX_CHAPTERS; int question = getRandomQuestion(trueFalseCounts[chapter]); generateQuestion(3, chapter, question, currentIndex);
printf("请输入答案是否正确(1错误/2正确,3提前交卷): "); int isCorrect; scanf("%d", &isCorrect);
if (isCorrect == 3) { printf("提前交卷,未作答的题目将按错误处理。 "); goto finish; }
if (isCorrect == 2) score += 1; }
finish: score += (TOTAL_SINGLE + TOTAL_MULTIPLE + TOTAL_TRUE_FALSE - currentIndex + 1) * 0;
printf(" 试卷完成,您的总得分是: %d 分 ", score);
return 0; }
|