package szys;
import java.util.Random;
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("请输入出题题数:");
int sum = scanner.nextInt();
//int c=scanner.nextInt();
/*int sum = 0,c = 0;
sum(sum);
fanwei(c);*/
int[] arr1=new int[sum*2];
int[] xuhao=new int[sum];
int[] shu1=new int[sum];
int[] fuhao=new int[4];
int[] shu2=new int[sum];
randomArr(arr1);
/*for(int i=0;i<rand.length;i++) {
System.out.println(rand[i]);
}*/
System.out.println("是否出现乘除运算,是输入1,否输入0");
//Scanner scanner=new Scanner(System.in);
int x=scanner.nextInt();
int k=0,m=0,right=0;
switch(x) {
case 0:
//String[] operate=new String[]{"+","-"};
Random rand=new Random();
for(int i=0;i<arr1.length;i=i+2){
int rand1=rand.nextInt(2);
if(rand1==0) {
System.out.println(k+1+". "+arr1[i]+'+'+arr1[i+1]+"=");
int jieguo=scanner.nextInt();
if(arr1[i]+arr1[i+1]==jieguo) {
System.out.println("正确!");right++;
}
else {
System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=0;shu2[m]=arr1[i+1]; m++; }
}
else if(rand1==1) {
System.out.println(k+1+". "+arr1[i]+'-'+arr1[i+1]+"=");
int jieguo=scanner.nextInt();
if(arr1[i]-arr1[i+1]==jieguo) {
System.out.println("正确!");right++;
}
else {
System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=1;shu2[m]=arr1[i+1]; m++; }
}
++k;}
break;
case 1:
Random rand2=new Random();
for(int i=0;i<arr1.length;i=i+2){
int rand1=rand2.nextInt(4);
if(rand1==0) {
System.out.println(k+1+". "+arr1[i]+'+'+arr1[i+1]+"=");
int jieguo=scanner.nextInt();
if(arr1[i]+arr1[i+1]==jieguo) {
System.out.println("正确!");right++;
}
else {
System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=0;shu2[m]=arr1[i+1]; m++; }
}
else if(rand1==1) {
System.out.println(k+1+". "+arr1[i]+'-'+arr1[i+1]+"=");
int jieguo=scanner.nextInt();
if(arr1[i]-arr1[i+1]==jieguo) {
System.out.println("正确!");right++;
}
else {
System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=1;shu2[m]=arr1[i+1]; m++; }
}
else if(rand1==2) {
System.out.println(k+1+". "+arr1[i]+'*'+arr1[i+1]+"=");
int jieguo=scanner.nextInt();
if(arr1[i]*arr1[i+1]==jieguo) {
System.out.println("正确!");right++;
}
else {
System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=2;shu2[m]=arr1[i+1]; m++; }
}
else if(rand1==3) {
System.out.println(k+1+". "+arr1[i]+'/'+arr1[i+1]+"=");
int jieguo=scanner.nextInt();
if(arr1[i]/arr1[i+1]==jieguo) {
System.out.println("正确!");right++;
}
else {
System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=3;shu2[m]=arr1[i+1]; m++; }
}
++k;}
break;
}
System.out.println("正确率:"+(right*100)/sum+"%");
System.out.println("是否重做错题?是输入1,否输入0");
int cout=scanner.nextInt();
while(cout==1) {
String[] operate=new String[]{"+","-","*","/"};
for(int i=0;i<m;i++) {
//System.out.println(xuhao[i]+'.');
System.out.println(shu1[i]+operate[fuhao[i]]+shu2[i]+'=');
int jieguo1=scanner.nextInt();
if(fuhao[i]==0) {
while(jieguo1!=shu1[i]+shu2[i]) {
System.out.println("错误,请重新输入答案:");
jieguo1=scanner.nextInt();
}
System.out.println("正确");
}
else if(fuhao[i]==1) {
while(jieguo1!=shu1[i]-shu2[i]) {
System.out.println("错误,请重新输入答案:");
jieguo1=scanner.nextInt();
}
System.out.println("正确");
}
else if(fuhao[i]==2) {
while(jieguo1!=shu1[i]*shu2[i]) {
System.out.println("错误,请重新输入答案:");
jieguo1=scanner.nextInt();
}
System.out.println("正确");
}
else if(fuhao[i]==3) {
while(jieguo1!=shu1[i]/shu2[i]) {
System.out.println("错误,请重新输入答案:");
jieguo1=scanner.nextInt();
}
System.out.println("正确");
}
}
System.out.println();
System.out.println();
System.out.println("已结束!!!");
break;
}
if(cout==0) {System.out.println("已退出!!!");}
}
public static int[] randomArr(int[] arr) {
Random rd = new Random();
for (int i = 0; i < arr.length; i++) {
int count = 0;
// arr[i]=rd.nextInt(10)+1;
int temp = rd.nextInt(100);
for (int j = 0; j < arr.length; j++) {
if (arr[j] == temp) {
count++;
}
}if (count>0){
i--;
}else{
arr[i] = temp;
}
}
return arr;
}
}