package sizeyunsuan2; import java.util.*; import java.util.Random; public class si_ze_yun_suan2 { char fu_hao[]={'+','-','*','/'}; int a[]=new int[15]; //暂时存放新生成的式子 String[][] ti_mu=new String[3][1000]; //存放运算完之后的式子 int da_an[][]=new int[3][1000]; int cao_zuo_ge_shu,kuo_hao=0; int cheng_chu=2,num=30,fan_wei=100; String[][] cuo_ti=new String[3][1000]; //用于存放错题 int[][] cuo_da_an=new int[3][1000]; int[] cuo_num={0,0,0}; //用于存放错题数目 int[] temp={0,0,0}; int kuo_wei_zhi; // **************************************主函数 public static void main(String args[]) { enum1(); } //************************************** public static void enum1() { int choose=1; si_ze_yun_suan2 c= new si_ze_yun_suan2(); while(choose==1){ System.out.println("**************"); System.out.println("1.参数设置"); System.out.println("2.小学二年级口算题"); System.out.println("3.小学三年级口算题"); System.out.println("4.小学四年级口算题"); System.out.println("5.错题集"); System.out.println("6.退出"); System.out.println("**************"); Scanner input = new Scanner(System.in); int x = input.nextInt(); switch(x){ case 1:c.can_shu(); break; case 2:c.magic(2,0,2,x-2); //magic(czgs1,kuo_hao,cheng_chu,classes) break; case 3:c.magic(4,0,2,x-2); break; case 4:c.magic(4,1,4,x-2); break; case 5:c.cuo_ti_ji(); break; case 6:choose=0; System.out.println("再见!"); break; default:System.out.println("错误数字!");break; } } } //************************************** void can_shu() { Scanner input=new Scanner(System.in); System.out.println("出题数? "); num=input.nextInt(); System.out.println("操作数数值范围?"); fan_wei=input.nextInt(); } //************************************ void cuo_ti(int classes) { if(cuo_num[classes]==0){ System.out.println("无错题"); } else{ System.out.print(" *****错题***** "); for(int i=0;i<cuo_num[classes];i++) { System.out.print((i+1)); System.out.print("."); System.out.print(cuo_ti[classes][i]); System.out.print(cuo_da_an[classes][i]); System.out.println(); } System.out.println("正确率:"+(double)(temp[classes]*num-cuo_num[classes])*100/(temp[classes]*num)+"%"); } } //*******************************5.错题集 void cuo_ti_ji() { System.out.println("几年级?"); Scanner input=new Scanner(System.in); int x=input.nextInt(); if(x>=2&&x<=4) cuo_ti(x-2); else {System.out.print("错误数字!"); cuo_ti_ji();} } //************************************* int zuoti(int classes,int i) { int daan1; Scanner input=new Scanner(System.in); daan1=input.nextInt(); if(daan1==da_an[classes][i]) { System.out.print("*****正确***** "); return 1; } else { System.out.print("*****错误***** "); cuo_ti[classes][cuo_num[classes]]=ti_mu[classes][i]; cuo_da_an[classes][cuo_num[classes]]=da_an[classes][i]; cuo_num[classes]++; return 0; } } //*********************************** int yun_suan(int kh,int kuo_wei_zhi) { int daan=0,w=0; if(kh==1) { int k=kuo_wei_zhi+1; switch(a[k]%cheng_chu){ case 0:a[k-1]+=a[k+1]; break; case 1:a[k-1]-=a[k+1]; break; case 2: a[k-1]=a[k-1]*a[k+1]; break; case 3: a[k-1]=a[k-1]/a[k+1]; break; } for(int j=k;j<cao_zuo_ge_shu*2+2;j++) a[j]=a[j+2]; } for(int k=1;k<(cao_zuo_ge_shu)*2-2;k+=2) { switch(a[k]%cheng_chu){ case 2: a[k-1]=a[k-1]*a[k+1]; for(int j=k;j<cao_zuo_ge_shu*2+2;j++) a[j]=a[j+2]; k-=2; break; case 3: a[k-1]=a[k-1]/a[k+1]; for(int j=k;j<cao_zuo_ge_shu*2+2;j++) a[j]=a[j+2]; k-=2; break; } } daan+=a[0]; for(int k=1;k<cao_zuo_ge_shu*2-2;k+=2) { if(a[k]%cheng_chu==0) daan+=a[k+1]; else daan-=a[k+1]; } for(int j=0;j<cao_zuo_ge_shu*2;j++) { a[j]=0; } return daan; } //**************************************** static int cha_chong(int i,int czgs,int[] a,int coc) { int same=0; for(int j=0;j<i;j++) { for(int k=0;k<czgs*2-1;k++) { if(a[j]==a[k]) same++; if(a[k+1]==0&&a[k]%coc==3&&k%2==1) return 0; if(k%2==1&&a[k]%coc==3&&a[k-1]%a[k+1]!=0) return 0; if(k%2==1&&a[k]%coc==3&&a[k-1]<a[k+1]) return 0; } if(same==czgs*2-1) return 0; else return 1; } return 1; } //*************************************** void ji_lu(int[] a,int classes,int i,int kh,int cheng_c,int k_w_z) { kuo_wei_zhi=k_w_z; ti_mu[classes][i]=" "; for(int j=0;j<cao_zuo_ge_shu*2-2;j+=2) { if(kh==1&&j==kuo_wei_zhi) ti_mu[classes][i]+='('; ti_mu[classes][i]+=a[j]; if(kh==1&&j==kuo_wei_zhi+2) ti_mu[classes][i]+=')'; ti_mu[classes][i]+=fu_hao[a[j+1]%cheng_c]; } ti_mu[classes][i]+=a[cao_zuo_ge_shu*2-2]; ti_mu[classes][i]+='='; } //************************************** void magic(int czgs1,int kuo_h,int cheng_c,int classes) { temp[classes]++; cao_zuo_ge_shu=czgs1; kuo_hao=kuo_h; cheng_chu=cheng_c; int t,kh=0; Random rand1 = new Random(); Random x = new Random(); for(int i=0;i<num;i++) { for(int k=0;k<cao_zuo_ge_shu*2-1;k++) { if(kuo_h==1&&k==0) { kuo_wei_zhi=rand1.nextInt(fan_wei+1)%cao_zuo_ge_shu; kh=rand1.nextInt(fan_wei+1)%2; } a[k]=rand1.nextInt(fan_wei+1); //随机生成 } t=cha_chong(i,czgs1,a,cheng_c); //查重 if(t!=0) { ji_lu(a,classes,i,kh,cheng_c,kuo_wei_zhi); da_an[classes][i]=yun_suan(kh,kuo_wei_zhi); System.out.print(ti_mu[classes][i]); zuoti(classes,i); } else i--; } cuo_ti(classes); } }
package
sizeyunsuan2;
import
java.util.*;
import
java.util.Random;
public
class
si_ze_yun_suan2 {
char
fu_hao[]={
'+'
,
'-'
,
'*'
,
'/'
};
int
a[]=
new
int
[
15
];
//暂时存放新生成的式子
String[][] ti_mu=
new
String[
3
][
1000
];
//存放运算完之后的式子
int
da_an[][]=
new
int
[
3
][
1000
];
int
cao_zuo_ge_shu,kuo_hao=
0
;
int
cheng_chu=
2
,num=
30
,fan_wei=
100
;
String[][] cuo_ti=
new
String[
3
][
1000
];
//用于存放错题
int
[][] cuo_da_an=
new
int
[
3
][
1000
];
int
[] cuo_num={
0
,
0
,
0
};
//用于存放错题数目
int
[] temp={
0
,
0
,
0
};
int
kuo_wei_zhi;
// **************************************主函数
public
static
void
main(String args[])
{
enum1();
}
//**************************************
public
static
void
enum1()
{
int
choose=
1
;
si_ze_yun_suan2 c=
new
si_ze_yun_suan2();
while
(choose==
1
){
System.out.println(
"**************"
);
System.out.println(
"1.参数设置"
);
System.out.println(
"2.小学二年级口算题"
);
System.out.println(
"3.小学三年级口算题"
);
System.out.println(
"4.小学四年级口算题"
);
System.out.println(
"5.错题集"
);
System.out.println(
"6.退出"
);
System.out.println(
"**************"
);
Scanner input =
new
Scanner(System.in);
int
x = input.nextInt();
switch
(x){
case
1
:c.can_shu();
break
;
case
2
:c.magic(
2
,
0
,
2
,x-
2
);
//magic(czgs1,kuo_hao,cheng_chu,classes)
break
;
case
3
:c.magic(
4
,
0
,
2
,x-
2
);
break
;
case
4
:c.magic(
4
,
1
,
4
,x-
2
);
break
;
case
5
:c.cuo_ti_ji();
break
;
case
6
:choose=
0
;
System.out.println(
"再见!"
);
break
;
default
:System.out.println(
"错误数字!"
);
break
;
}
}
}
//**************************************
void
can_shu()
{
Scanner input=
new
Scanner(System.in);
System.out.println(
"出题数? "
);
num=input.nextInt();
System.out.println(
"操作数数值范围?"
);
fan_wei=input.nextInt();
}
//************************************
void
cuo_ti(
int
classes)
{
if
(cuo_num[classes]==
0
){
System.out.println(
"无错题"
);
}
else
{
System.out.print(
"
*****错题*****
"
);
for
(
int
i=
0
;i<cuo_num[classes];i++)
{
System.out.print((i+
1
));
System.out.print(
"."
);
System.out.print(cuo_ti[classes][i]);
System.out.print(cuo_da_an[classes][i]);
System.out.println();
}
System.out.println(
"正确率:"
+(
double
)(temp[classes]*num-cuo_num[classes])*
100
/(temp[classes]*num)+
"%"
);
}
}
//*******************************5.错题集
void
cuo_ti_ji()
{
System.out.println(
"几年级?"
);
Scanner input=
new
Scanner(System.in);
int
x=input.nextInt();
if
(x>=
2
&&x<=
4
) cuo_ti(x-
2
);
else
{System.out.print(
"错误数字!"
); cuo_ti_ji();}
}
//*************************************
int
zuoti(
int
classes,
int
i)
{
int
daan1;
Scanner input=
new
Scanner(System.in);
daan1=input.nextInt();
if
(daan1==da_an[classes][i])
{
System.out.print(
"*****正确*****
"
);
return
1
;
}
else
{
System.out.print(
"*****错误*****
"
);
cuo_ti[classes][cuo_num[classes]]=ti_mu[classes][i];
cuo_da_an[classes][cuo_num[classes]]=da_an[classes][i];
cuo_num[classes]++;
return
0
;
}
}
//***********************************
int
yun_suan(
int
kh,
int
kuo_wei_zhi)
{
int
daan=
0
,w=
0
;
if
(kh==
1
)
{
int
k=kuo_wei_zhi+
1
;
switch
(a[k]%cheng_chu){
case
0
:a[k-
1
]+=a[k+
1
];
break
;
case
1
:a[k-
1
]-=a[k+
1
];
break
;
case
2
: a[k-
1
]=a[k-
1
]*a[k+
1
];
break
;
case
3
: a[k-
1
]=a[k-
1
]/a[k+
1
];
break
;
}
for
(
int
j=k;j<cao_zuo_ge_shu*
2
+
2
;j++) a[j]=a[j+
2
];
}
for
(
int
k=
1
;k<(cao_zuo_ge_shu)*
2
-
2
;k+=
2
)
{
switch
(a[k]%cheng_chu){
case
2
:
a[k-
1
]=a[k-
1
]*a[k+
1
];
for
(
int
j=k;j<cao_zuo_ge_shu*
2
+
2
;j++) a[j]=a[j+
2
];
k-=
2
;
break
;
case
3
:
a[k-
1
]=a[k-
1
]/a[k+
1
];
for
(
int
j=k;j<cao_zuo_ge_shu*
2
+
2
;j++) a[j]=a[j+
2
];
k-=
2
;
break
;
}
}
daan+=a[
0
];
for
(
int
k=
1
;k<cao_zuo_ge_shu*
2
-
2
;k+=
2
)
{
if
(a[k]%cheng_chu==
0
) daan+=a[k+
1
];
else
daan-=a[k+
1
];
}
for
(
int
j=
0
;j<cao_zuo_ge_shu*
2
;j++)
{
a[j]=
0
;
}
return
daan;
}
//****************************************
static
int
cha_chong(
int
i,
int
czgs,
int
[] a,
int
coc)
{
int
same=
0
;
for
(
int
j=
0
;j<i;j++)
{
for
(
int
k=
0
;k<czgs*
2
-
1
;k++)
{
if
(a[j]==a[k]) same++;
if
(a[k+
1
]==
0
&&a[k]%coc==
3
&&k%
2
==
1
)
return
0
;
if
(k%
2
==
1
&&a[k]%coc==
3
&&a[k-
1
]%a[k+
1
]!=
0
)
return
0
;
if
(k%
2
==
1
&&a[k]%coc==
3
&&a[k-
1
]<a[k+
1
])
return
0
;
}
if
(same==czgs*
2
-
1
)
return
0
;
else
return
1
;
}
return
1
;
}
//***************************************
void
ji_lu(
int
[] a,
int
classes,
int
i,
int
kh,
int
cheng_c,
int
k_w_z)
{
kuo_wei_zhi=k_w_z;
ti_mu[classes][i]=
" "
;
for
(
int
j=
0
;j<cao_zuo_ge_shu*
2
-
2
;j+=
2
)
{
if
(kh==
1
&&j==kuo_wei_zhi) ti_mu[classes][i]+=
'('
;
ti_mu[classes][i]+=a[j];
if
(kh==
1
&&j==kuo_wei_zhi+
2
) ti_mu[classes][i]+=
')'
;
ti_mu[classes][i]+=fu_hao[a[j+
1
]%cheng_c];
}
ti_mu[classes][i]+=a[cao_zuo_ge_shu*
2
-
2
];
ti_mu[classes][i]+=
'='
;
}
//**************************************
void
magic(
int
czgs1,
int
kuo_h,
int
cheng_c,
int
classes)
{
temp[classes]++;
cao_zuo_ge_shu=czgs1;
kuo_hao=kuo_h;
cheng_chu=cheng_c;
int
t,kh=
0
;
Random rand1 =
new
Random();
Random x =
new
Random();
for
(
int
i=
0
;i<num;i++)
{
for
(
int
k=
0
;k<cao_zuo_ge_shu*
2
-
1
;k++)
{
if
(kuo_h==
1
&&k==
0
)
{
kuo_wei_zhi=rand1.nextInt(fan_wei+
1
)%cao_zuo_ge_shu;
kh=rand1.nextInt(fan_wei+
1
)%
2
;
}
a[k]=rand1.nextInt(fan_wei+
1
);
//随机生成
}
t=cha_chong(i,czgs1,a,cheng_c);
//查重
if
(t!=
0
)
{
ji_lu(a,classes,i,kh,cheng_c,kuo_wei_zhi);
da_an[classes][i]=yun_suan(kh,kuo_wei_zhi);
System.out.print(ti_mu[classes][i]);
zuoti(classes,i);
}
else
i--;
}
cuo_ti(classes);
}
}