-
Notifications
You must be signed in to change notification settings - Fork 9
/
final1.cpp
491 lines (467 loc) · 8.93 KB
/
final1.cpp
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#include<stdio.h>
#include<bits/stdc++.h>
#include <time.h>
#include <unistd.h>
using namespace std;
int change(string s){//传入string类型参数
string a("一");
string b("二");
string c("三");
string d("四");
string e("五");
string f("六");
if (s.substr(0,2)==a||s.substr(0,2)==b)
return 1; //一二年级返回1
if (s.substr(0,2)==c||s.substr(0,2)==d)
return 2; //三四年级返回2
if (s.substr(0,2)==e||s.substr(0,2)==f)
return 3;//五六年级返回3
}
//生成随机数
int grade1_num()
{
srand((unsigned)time(0)+(unsigned)rand());
int a=rand()%100;
sleep(1);
return a;
}
int grade2_num()
{
srand((unsigned)time(0)+(unsigned)rand());
int a=rand()%10000;
sleep(1);
return a;
}
double grade3_num()
{
srand((unsigned)time(0)+(unsigned)rand());
int a=rand()%10001;
double b=(double)a/10000.0;
srand(time(NULL));
int c=rand()%10000;
b+=(double)c;
sleep(1);
return b;
}
//生成随机运算符
char grade12_char()
{
char s[2]={'+','-'};
srand((unsigned)time(0)+(unsigned)rand());
int a=rand()%2;
return s[a];
}
char grade3_char()
{
char s[4]={'+','-','*','/'};
srand((unsigned)time(0)+(unsigned)rand());
int a=rand()%4;
return s[a];
}
//一二年级计算
int flag=0;
int grade1_2()
{
int number;
srand(time(NULL));
int i,a,b,c,d,op,result,num;
char s;
int ans,input;
cin>>number;
for(i=0;i<number;i++)
{
a=rand()%101;
b=rand()%101;
c=rand()%101;
d=rand()%101;
op=rand()%16;
switch(op){
case 0:
cout<<a<<"+"<<b<<"="<<endl;
result=a+b;
cin>>ans;
if(ans!=result)flag++;
break;
case 1:
cout<<a<<"-"<<b<<"="<<endl;
result=a-b;
cin>>ans;
if(ans!=result)flag++;
break;
case 2:
cout<<a<<"+"<<b<<"+"<<c<<"="<<endl;
result=a+b+c;
cin>>ans;
if(ans!=result)flag++;
break;
case 3:
cout<<a<<"+"<<b<<"-"<<c<<"="<<endl;
result=a+b-c;
cin>>ans;
if(ans!=result)flag++;
break;
case 4:
cout<<a<<"-"<<b<<"-"<<c<<"="<<endl;
result=a-b-c;
cin>>ans;
if(ans!=result)flag++;
break;
case 5:
cout<<a<<"-("<<b<<"-"<<c<<")"<<"="<<endl;
result=a-(b-c);
cin>>ans;
if(ans!=result)flag++;
break;
case 6:
cout<<a<<"-"<<b<<"+"<<c<<"="<<endl;
result=a-b+c;
cin>>ans;
if(ans!=result)flag++;
break;
case 7:
cout<<a<<"-("<<b<<"+"<<c<<")"<<"="<<endl;
result=a-(b+c);
cin>>ans;
if(ans!=result)flag++;
break;
case 8:
cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<endl;
result=a+b+c+d;
cin>>ans;
if(ans!=result)flag++;
break;
case 9:
cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<endl;
result=a+b+c-d;
cin>>ans;
if(ans!=result)flag++;
break;
case 10:
cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<endl;
result=a+b-c-d;
cin>>ans;
if(ans!=result)flag++;
break;
case 11:
cout<<a<<"+"<<b<<"-("<<c<<"-"<<d<<")"<<"="<<endl;
result=a+b-(c-d);
cin>>ans;
if(ans!=result)flag++;
break;
case 12:
cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<endl;
result=a-b-c-d;
cin>>ans;
if(ans!=result)flag++;
break;
case 13:
cout<<a<<"-"<<b<<"-("<<c<<"-"<<d<<")"<<"="<<endl;
result=a-b-(c-d);
cin>>ans;
if(ans!=result)flag++;
break;
case 14:
cout<<a<<"-("<<b<<"-"<<c<<"-"<<d<<")"<<"="<<endl;
result=a-(b-c-d);
cin>>ans;
if(ans!=result)flag++;
break;
case 15:
cout<<a<<"-("<<b<<"-"<<c<<")"<<"-"<<d<<"="<<endl;
result=a-(b-c)-d;
cin>>ans;
if(ans!=result)flag++;
break;}
}
return flag ;
}
//三四年级计算
int grade3_4()
{
int number; //number为题目数目
srand(time(NULL));
float result,ans;
int op;
cin>>number;
for(int i=0;i<number;i++){
int ele_num=rand()%2+2; //ele_num为该题元素个数
if(ele_num==2){
int a=rand()%10001;
int b=rand()%10001;
op=rand()%4;
switch(op)
{
case 0:
cout<<a<<"+"<<b<<"="<<endl;
result=a+b;
cin>>ans;
if(ans!=result)flag++;
break;
case 1:
cout<<a<<"-"<<b<<"="<<endl;
result=a-b;
cin>>ans;
if(ans!=result)flag++;
break;
case 2:
cout<<a<<"*"<<b<<"="<<endl;
result=a*b;
cin>>ans;
if(ans!=result)flag++;
break;
case 3:
cout<<a<<"/"<<b<<"="<<endl;
result=a/b;
cin>>ans;
if(ans!=result)flag++;
break;
}
}
else{ //ele_num=3;
int a=rand()%10001;
int b=rand()%10001;
int c=rand()%10001;
op=rand()%20;
switch(op)
{
case 1:
cout<<a<<"+"<<b<<"-"<<c<<"="<<endl;
result=a+b-c;
cin>>ans;
if(ans!=result)flag++;
break;
case 2:
cout<<a<<"+"<<b<<"+"<<c<<"="<<endl;
result=a+b+c;
cin>>ans;
if(ans!=result)flag++;
break;
case 3:
cout<<a<<"+"<<b<<"="<<endl;
result=a+b*c;
cin>>ans;
if(ans!=result)flag++;
break;
case 4:
cout<<a<<"+"<<b<<"="<<endl;
result=a+b/c;
cin>>ans;
if(ans!=result)flag++; //+
break;
case 5:
cout<<a<<"-"<<b<<"-"<<c<<"="<<endl;
result=a-b-c;
cin>>ans;
if(ans!=result)flag++;
break;
case 6:
cout<<a<<"-"<<b<<"+"<<c<<"="<<endl;
result=a-b+c;
cin>>ans;
if(ans!=result)flag++;
break;
case 7:
cout<<a<<"-"<<b<<"*"<<c<<"="<<endl;
result=a-b*c;
cin>>ans;
if(ans!=result)flag++;
break;
case 8:
cout<<a<<"-"<<b<<"/"<<c<<"="<<endl;
result=a-b/c;
cin>>ans;
if(ans!=result)flag++;
break;
case 9:
cout<<a<<"*"<<b<<"-"<<c<<"="<<endl;
result=a*b-c;
cin>>ans;
if(ans!=result)flag++;
break;
case 10:
cout<<a<<"*"<<b<<"+"<<c<<"="<<endl;
result=a*b+c;
cin>>ans;
if(ans!=result)flag++;
break;
case 11:
cout<<"("<<a<<"+"<<b<<")"<<"*"<<c<<"="<<endl; //括号开始
result=(a+b)*c;
cin>>ans;
if(ans!=result)flag++;
break;
case 12:
cout<<"("<<a<<"-"<<b<<")"<<"-"<<c<<"="<<endl;
result=(a-b)*c;
cin>>ans;
if(ans!=result)flag++;
break;
case 13:
cout<<"("<<a<<"+"<<b<<")"<<"/"<<c<<"="<<endl;
result=(a+b)/c;
cin>>ans;
if(ans!=result)flag++;
break;
case 14:
cout<<"("<<a<<"-"<<b<<")"<<"/"<<c<<"="<<endl;
result=(a-b)*c;
cin>>ans;
if(ans!=result)flag++;
break;
case 15:
cout<<a<<"*"<<"("<<b<<"+"<<c<<")"<<"="<<endl;
result=a*(b+c);
cin>>ans;
if(ans!=result)flag++;
break;
case 16:
cout<<a<<"*"<<"("<<b<<"-"<<c<<")"<<"="<<endl;
result=a*(b-c);
cin>>ans;
if(ans!=result)flag++;
break;
case 17:
cout<<a<<"/"<<"("<<b<<"+"<<c<<")"<<"="<<endl;
result=a/(b+c);
cin>>ans;
if(ans!=result)flag++;
break;
case 18:
cout<<a<<"/"<<"("<<b<<"-"<<c<<")"<<"="<<endl;
result=a/(b-c);
cin>>ans;
if(ans!=result)flag++;
break;
case 19:
cout<<a<<"-"<<"("<<b<<"+"<<c<<")"<<"="<<endl;
result=a-(b+c);
cin>>ans;
if(ans!=result)flag++;
break;
case 20:
cout<<a<<"-"<<"("<<b<<"-"<<c<<")"<<"="<<endl;
result=a-(b-c);
cin>>ans;
if(ans!=result)flag++;
break;
}
}
}
return flag;
}
//五六年级计算
int grade5_6()
{ int flag = 0;
int j,xh;
srand(time(0));
scanf("%d",&xh);
for(j=0;j<xh;j++)
{
int i;
int num1 = rand()%4;
int num3 = rand()%3+2;
char s[4] = {'+','-','*','/'};
double shu[num3];
char ys[num3];
int l = 0;
int k = 0;
for(i=0;i<num3;i++)
{
int num = rand()%4;
double num2 = (double)rand()/RAND_MAX*(10000-0)+0;
shu[l] = num2;
l += 1;
printf("%f",num2);
if(i!=num3-1)
{
ys[k] = s[num];
k += 1;
printf("%c",s[num]);
}
if(i==num3-1)
printf("=");
}
printf("\n");
int js;
int m = 0;
for(i=0;i<k;i++)
{
switch(ys[i])
{
case '*':
shu[i+1] = shu[i+1]*shu[i];
ys[i]=']';
break;
case '/':
shu[i+1] = shu[i]+shu[i+1];
ys[i]=']';
break;
}
}
for(i=0;i<k;i++)
{
if(ys[i]==']')
{
shu[i] = 0;
}
}
int shu1[5];
char ys1[4];
for(i=0;i<k;i++)
{
switch(ys[i])
{
case ']':
shu[i+1] = shu[i] + shu[i+1];
break;
case '+':
shu[i+1] = shu[i] + shu[i+1];
break;
case '-':
shu[i+1] = shu[i] - shu[i+1];
break;
}
}
double sl;
double p;
int qs;
qs = (int)(shu[num3-1]*100+0.5);
p = qs /100.0;
scanf("%f",&sl);
if(p != qs)
{flag++;
}
//printf("%.2f\n ",shu[num3-1]);
}
return flag;
}
//判断
int panduan(double input,double ans)
{
if(ans!=input)
{
flag++;
}
}
int main(){
printf("请输入你的年级\n");
string a;
int b;
int grade;
cin>>a;
printf("请输入题目数\n");
grade=change(a);
//cout<<grade;
switch(grade){
case 1: grade1_2();
break;
case 2: grade3_4();
break;
case 3: grade5_6();
break;
}
if(flag==0)
cout<<"结束!全部正确,太棒了!"<<endl;
else
cout<<"结束!错了" <<flag <<"题哦" <<endl;
}