zoukankan      html  css  js  c++  java
  • 二柱子问题最终版

    10.20

    代码部分:

    package lianxi;
    import java.util.Scanner;
    import java.lang.Thread;
    public class reduam4 {
    public static void main(String[] args) {//主函数
    int a=0;
    Scanner in=new Scanner(System.in);
    ZhuJieMian();
    System.out.println("请输入你想进行的操作");
    a=in.nextInt();
    do {//控制循环

    switch(a) {
    case 1:SheCan();break;
    case 2:XiaoEr();break;
    case 3:XiaoSan();break;
    case 4:XiaoSi();break;
    case 5:CuoTiJi();break;
    case 6:CuoTiChongZuo();
    break;
    }
    System.out.println("请输入你想进行的操作");
    a=in.nextInt();
    }while(a!=0);

    }
    public static void SheCan() {//设置参数
    Scanner in=new Scanner(System.in);
    System.out.println("出题个数为");
    chutigeshu=in.nextInt();
    System.out.println("最大值为");
    zuidazhi=in.nextInt();
    System.out.println("最小值为");
    zuixiaozhi=in.nextInt();
    }
    public static void ZhuJieMian() {//设置主界面
    System.out.println("1.参数设置");
    System.out.println("2.小学二年级口算题");
    System.out.println("3.小学三年及口算题");
    System.out.println("4.小学四年级口算题");
    System.out.println("5.错题集");
    System.out.println("0.退出循环");
    }
    public static void XiaoEr() {//二年级方法
    Scanner in=new Scanner(System.in);
    Integer[] q1=new Integer[chutigeshu];
    Integer[] w1=new Integer[chutigeshu];
    Character[] e1=new Character[chutigeshu];
    int i=0,j;
    int a1,a;
    int b;
    int c,daan;
    int h1=0,h2=0;
    char x='+';
    for(i=0;i<chutigeshu;i++) {
    a1=(int)(Math.random()*(zuidazhi-zuixiaozhi)+(zuixiaozhi));
    b=(int)(Math.random()*(zuidazhi-zuixiaozhi)+(zuixiaozhi));
    c=(int)(Math.random()*4+1);

    switch(c) {
    case 1:x='+';break;
    case 2:x='-';break;
    case 3:x='*';break;
    case 4:x='/';break;
    }
    if(c==4) {
    if(a1%b!=0) {
    do {
    b=(int)(Math.random()*(zuidazhi-zuixiaozhi)+(zuixiaozhi));
    }while(a1%b!=0);
    }
    }
    q1[i]=a1;
    w1[i]=b;
    e1[i]=x;
    for(j=0;j<i;j++) {
    if(q1[j]==q1[i]&&w1[j]==w1[i]&&e1[j]==e1[i])
    break;
    }

    System.out.println((i+1)+":"+a1+x+b+"=");
    if(x=='+') {
    a=a1+b;
    }
    else if(x=='-') {
    a=a1-b;
    }
    else if(x=='*') {
    a=a1*b;
    }
    else {
    a=a1/b;
    }
    daan=in.nextInt();
    System.out.println("正确答案:"+a);
    if(daan==a) {
    System.out.println("答对了");
    h1++;
    }
    else {
    System.out.println("答错了,计入错题集");
    h2++;
    q[s]=a1;
    w[s]=b;
    e[s]=x;
    daer[s]=a;
    s++;
    }
    }
    System.out.println("答对了"+h1+"道题,答错了"+h2+"道题");
    System.out.println("正确率:"+((double)h1/(double)chutigeshu));
    System.out.println("错题有:");
    for(i=0;i<s;i++) {
    System.out.println(q[i]+""+e[i]+""+w[i]+"=");
    }
    }
    public static void XiaoSan() {//三年级方法
    Scanner in=new Scanner(System.in);
    System.out.println("请输入操作数个数:(不超过四个)");
    int caozuoshugeshu=in.nextInt();
    Integer[][] r1=new Integer[chutigeshu][caozuoshugeshu];
    Integer[][] t1=new Integer[chutigeshu][caozuoshugeshu];
    Character[][] x1=new Character[chutigeshu][caozuoshugeshu];
    int i=0,j,h,h1=0,h2=0;
    int total=0;
    for(i=0;i<chutigeshu;i++) {
    for(j=0;j<caozuoshugeshu;j++) {
    r1[i][j]=(int)(Math.random()*(zuidazhi-zuixiaozhi)+zuixiaozhi);
    }
    for(j=0;j<caozuoshugeshu-1;j++) {
    t1[i][j]=(int)(Math.random()*4+1);
    }
    t1[i][caozuoshugeshu-1]=32;
    for(j=0;j<caozuoshugeshu;j++) {
    switch(t1[i][j]) {
    case 1:x1[i][j]='+';break;
    case 2:x1[i][j]='-';break;
    case 3:x1[i][j]='*';break;
    case 4:x1[i][j]='/';break;
    case 32:x1[i][j]='=';break;
    }
    ChaChong(r1,x1,caozuoshugeshu,i);
    }
    total=r1[i][0];
    System.out.print((i+1)+":");
    for(j=0;j<caozuoshugeshu;j++) {
    System.out.print(r1[i][j]+""+x1[i][j]);
    }
    for(j=0;j<caozuoshugeshu;j++) {
    while((x1[i][j]=='*'||x1[i][j]=='/')&&j<caozuoshugeshu){

    if(x1[i][j]=='*') {
    total*=r1[i][j+1];
    }
    else {
    total/=r1[i][j+1];
    }
    j++;
    }
    if(x1[i][j]=='+'||x1[i][j]=='-') {
    int u=r1[i][j+1];
    if(x1[i][j]=='+') {
    while((x1[i][j+1]=='*'||x1[i][j+1]=='/')&&(j+1)<caozuoshugeshu){

    if(x1[i][j+1]=='*') {
    u*=r1[i][j+2];
    }
    else {
    u/=r1[i][j+2];
    }
    j++;
    }
    total+=u;
    }
    else if(x1[i][j]=='-') {
    while((x1[i][j+1]=='*'||x1[i][j+1]=='/')&&(j+1)<caozuoshugeshu){
    if(x1[i][j+1]=='*') {
    u*=r1[i][j+2];
    }
    else {
    u/=r1[i][j+2];
    }
    j++;
    }
    total-=u;
    }
    }
    }
    h=in.nextInt();

    System.out.println("正确答案:"+total);
    if(h==total) {
    System.out.println("答对了");
    h1++;
    }
    else {
    System.out.println("答错了");
    h2++;
    t2[s1]=i;
    dasan[s1]=total;
    s1++;
    }
    }
    for(i=0;i<s1;i++) {
    for(j=0;j<caozuoshugeshu;j++) {
    r[i][j]=r1[t2[i]][j];
    x[i][j]=x1[t2[i]][j];
    }
    }
    System.out.println("答对了"+h1+"道题,答错了"+h2+"道题");
    System.out.println("正确率:"+((double)h1/(double)chutigeshu));
    System.out.println("错题有:");
    for(i=0;i<s1;i++) {
    for(j=0;j<caozuoshugeshu;j++) {
    System.out.print(r1[t2[i]][j]+""+x1[t2[i]][j]);
    }
    System.out.println();
    }
    }
    public static void ChaChong(Integer[][] q,Character[][]w,int caozuoshugeshu,int p) {
    int i,j;//进行查重
    for(i=0;i<p;i++) {
    for(j=0;j<caozuoshugeshu;j++) {
    if(q[i][j]==q[p][j]||w[i][j]==w[p][j])
    break;
    }
    }
    }
    public static void CuoTiJi() {//错题集
    Scanner in=new Scanner(System.in);
    System.out.println("请输入你想查询哪个阶段的错题(二年级输2,三年级输3,四年级输4):");
    int a=in.nextInt();
    int i=0,j=0;
    switch(a) {
    case 2:for(i=0;i<s;i++) {
    System.out.println(q[i]+""+e[i]+""+w[i]+"=");
    }break;
    case 3:for(i=0;i<s1;i++) {
    for(j=0;j<caozuoshugeshu;j++) {
    System.out.print(r[t2[i]][j]+""+x[t2[i]][j]);
    }
    System.out.println();
    }break;
    case 4:for(i=0;i<s2;i++) {
    if(x2[t4[i]][0]=='+'||x2[t4[i]][0]=='-') {
    System.out.print("("+r2[t4[i]][0]+""+x2[t4[i]][0]+r2[t4[i]][1]+")"+x2[t4[i]][1]);
    for(j=2;j<caozuoshugeshu2;j++) {
    System.out.print(r2[t4[i]][j]+""+x2[t4[i]][j]);
    }
    }
    else {
    for(j=0;j<caozuoshugeshu2;j++) {
    System.out.print(r2[t4[i]][j]+""+x2[t4[i]][j]);
    }
    }
    System.out.println();
    }break;
    }
    }
    public static void XiaoSi() {//四年级运算题
    Scanner in=new Scanner(System.in);
    int i=0,j=0,total=0,h=0,h1=0,h2=0;
    int kuohao=0;
    System.out.println("请输入操作数个数(不超过五个):");
    int caozuoshugeshu2=in.nextInt();
    Integer[][] r3=new Integer[chutigeshu][caozuoshugeshu2];
    Integer[][] t3=new Integer[chutigeshu][caozuoshugeshu2];
    Character[][] x3=new Character[chutigeshu][caozuoshugeshu2];
    for(i=0;i<chutigeshu;i++) {
    for(j=0;j<caozuoshugeshu2;j++) {
    r3[i][j]=(int)(Math.random()*(zuidazhi-zuixiaozhi)+zuixiaozhi);
    }
    for(j=0;j<caozuoshugeshu2-1;j++) {
    t3[i][j]=(int)(Math.random()*4+1);
    }
    t3[i][caozuoshugeshu2-1]=32;
    for(j=0;j<caozuoshugeshu2;j++) {
    switch(t3[i][j]) {
    case 1:x3[i][j]='+';break;
    case 2:x3[i][j]='-';break;
    case 3:x3[i][j]='*';break;
    case 4:x3[i][j]='/';break;
    case 32:x3[i][j]='=';break;
    }
    ChaChong(r3,x3,caozuoshugeshu2,i);
    }
    total=r3[i][0];
    System.out.print((i+1)+":");
    if(x3[i][0]=='+'||x3[i][0]=='-') {
    System.out.print("("+r3[i][0]+""+x3[i][0]+""+r3[i][1]+")"+x3[i][1]);
    for(j=2;j<caozuoshugeshu2;j++) {

    System.out.print(r3[i][j]+""+x3[i][j]);
    }
    if(x3[i][0]=='+') {
    total=r3[i][0]+r3[i][1];
    }
    else {
    total=r3[i][0]-r3[i][1];
    }
    r3[i][1]=total;
    for(j=1;j<caozuoshugeshu2;j++) {
    while((x3[i][j]=='*'||x3[i][j]=='/')&&j<caozuoshugeshu2){

    if(x3[i][j]=='*') {
    total*=r3[i][j+1];
    }
    else {
    total/=r3[i][j+1];
    }
    j++;
    }
    if(x3[i][j]=='+'||x3[i][j]=='-') {
    int u=r3[i][j+1];
    if(x3[i][j]=='+') {
    while((x3[i][j+1]=='*'||x3[i][j+1]=='/')&&(j+1)<caozuoshugeshu2){

    if(x3[i][j+1]=='*') {
    u*=r3[i][j+2];
    }
    else {
    u/=r3[i][j+2];
    }
    j++;
    }
    total+=u;
    }

    else if(x3[i][j]=='-') {

    while((x3[i][j+1]=='*'||x3[i][j+1]=='/')&&(j+1)<caozuoshugeshu2){

    if(x3[i][j+1]=='*') {
    u*=r3[i][j+2];
    }
    else {
    u/=r3[i][j+2];

    }
    j++;
    }
    total-=u;
    }
    }
    }

    }
    else{
    for(j=0;j<caozuoshugeshu2;j++) {
    System.out.print(r3[i][j]+""+x3[i][j]);
    }

    for(j=0;j<caozuoshugeshu2;j++) {
    while((x3[i][j]=='*'||x3[i][j]=='/')&&j<caozuoshugeshu2){

    if(x3[i][j]=='*') {
    total*=r3[i][j+1];
    }
    else {
    total/=r3[i][j+1];
    }
    j++;
    }
    if(x3[i][j]=='+'||x3[i][j]=='-') {
    int u=r3[i][j+1];
    if(x3[i][j]=='+') {
    while((x3[i][j+1]=='*'||x3[i][j+1]=='/')&&(j+1)<caozuoshugeshu2){

    if(x3[i][j+1]=='*') {
    u*=r3[i][j+2];
    }
    else {
    u/=r3[i][j+2];
    }
    j++;
    }
    total+=u;
    }

    else if(x3[i][j]=='-') {

    while((x3[i][j+1]=='*'||x3[i][j+1]=='/')&&(j+1)<caozuoshugeshu2){

    if(x3[i][j+1]=='*') {
    u*=r3[i][j+2];
    }
    else {
    u/=r3[i][j+2];

    }
    j++;
    }
    total-=u;
    }
    }
    }
    }
    h=in.nextInt();
    System.out.println("正确答案:"+total);
    if(h==total) {
    System.out.println("答对了");
    h1++;
    }
    else {
    System.out.println("答错了");
    h2++;
    t4[s2]=i;
    dasi[s2]=total;
    s2++;
    }
    }
    for(i=0;i<s2;i++) {
    for(j=0;j<caozuoshugeshu2;j++) {
    r2[i][j]=r3[t4[i]][j];
    x2[i][j]=x3[t4[i]][j];
    }
    }
    System.out.println("答对了"+h1+"道题,答错了"+h2+"道题");
    System.out.println("正确率:"+((double)h1/(double)chutigeshu));
    System.out.println("错题有:");
    for(i=0;i<s2;i++) {
    if(x3[t4[i]][0]=='+'||x3[t4[i]][0]=='-') {
    if(x3[t4[i]][0]=='+')
    System.out.print("("+r3[t4[i]][0]+""+x3[t4[i]][0]+""+(r3[t4[i]][1]-r3[t4[i]][0])+")"+x3[t4[i]][1]);
    else
    System.out.print("("+r3[t4[i]][0]+""+x3[t4[i]][0]+""+(-r3[t4[i]][1]+r3[t4[i]][0])+")"+x3[t4[i]][1]);
    for(j=2;j<caozuoshugeshu2;j++) {
    System.out.print(r3[t4[i]][j]+""+x3[t4[i]][j]);
    }
    }
    else {
    for(j=0;j<caozuoshugeshu2;j++) {
    System.out.print(r3[t4[i]][j]+""+x3[t4[i]][j]);
    }
    }
    System.out.println();
    }
    }
    public static void CuoTiChongZuo() {//错题查重
    Scanner in=new Scanner(System.in);
    System.out.println("请输入你想重做哪个阶段的错题(二年级输2,三年级输3,四年级输4):");
    int a=in.nextInt();
    int i=0,j=0;
    int daan=0;
    switch(a) {
    case 2:for(i=0;i<s;i++) {
    System.out.println(q[i]+""+e[i]+""+w[i]+"=");
    daan=in.nextInt();
    System.out.println(daer[i]);
    if(daan==daer[i]) {
    System.out.println("答对了");
    }
    }break;
    case 3: for(i=0;i<s1;i++) {
    for(j=0;j<caozuoshugeshu;j++) {
    System.out.print(r[i][j]+""+x[i][j]);
    }
    daan=in.nextInt();
    System.out.println(dasan[i]);
    if(daan==dasan[i]) {
    System.out.println("答对了");
    }
    }break;
    case 4:for(i=0;i<s2;i++) {
    if(x2[i][0]=='+'||x2[i][0]=='-') {
    if(x2[i][0]=='+')
    System.out.print("("+r2[i][0]+""+x2[i][0]+""+(r2[i][1]-r2[i][0])+")"+x2[i][1]);
    else
    System.out.print("("+r2[i][0]+""+x2[i][0]+""+(-r2[i][1]+r2[i][0])+")"+x2[i][1]);
    for(j=2;j<caozuoshugeshu2;j++) {
    System.out.print(r2[i][j]+""+x2[i][j]);
    }
    daan=in.nextInt();
    System.out.println(dasi[i]);
    if(daan==dasi[i]) {
    System.out.println("答对了");
    }
    }
    else {
    for(j=0;j<caozuoshugeshu2;j++) {
    System.out.print(r2[i][j]+""+x2[i][j]);
    }
    daan=in.nextInt();
    System.out.println(dasi[i]);
    if(daan==dasi[i]) {
    System.out.println("答对了");
    }
    }
    }break;
    }
    }
    public static int chutigeshu=30,zuidazhi=100,zuixiaozhi=0,caozuoshugeshu=4,caozuoshugeshu2=5;
    public static Integer[] q=new Integer[30];
    public static Integer[] w=new Integer[30];
    public static Character[] e=new Character[30];
    public static Integer[] daer=new Integer[30];
    public static Integer[][] r=new Integer[chutigeshu][4];
    public static Character[][] x=new Character[chutigeshu][4];
    public static Integer[] dasan=new Integer[chutigeshu];
    public static Integer[][] r2=new Integer[chutigeshu][5];
    public static Character[][] x2=new Character[chutigeshu][5];
    public static Integer[] t2=new Integer[30];
    public static Integer[] t4=new Integer[30];
    public static Integer[] dasi=new Integer[chutigeshu];
    public static int s=0,s1=0,s2=0;
    }

    运行结果:

     

  • 相关阅读:
    读取列表下标
    字典dict详解
    使用mysql的长连接
    oauth授权协议的原理
    安装性能测试工具:sysbench和使用apache的ab
    发送邮件出现问题
    获取用户的真实ip
    清理代码的阅读笔记
    开发中三个经典的原则
    要干大事就不能把面子看得太重
  • 原文地址:https://www.cnblogs.com/092e/p/14145860.html
Copyright © 2011-2022 走看看