首页 > 其他 > 详细

9.26学习总结

时间:2022-05-27 23:30:38      阅读:258      评论:0      收藏:0      [点我收藏+]

(1)今日计划

四则运算第二阶段

(2)源代码

package size;
import java.util.*;
import java.lang.Math;
public class size {
    static int count=0;
    static int ccount=0;
    static int cuoticount=0;
    static int congzuosum=1;
    static int tishusum=0;
    static String []arr = new String[100000];
    static String []arr1 = new String[100000];
    static int []zqda = new int[100000];
    static int []cishu = new int[100000];
    static Scanner sc = new Scanner(System.in);
//生成随机符号
    public static char operator(int chengchu) {
        char op=‘ ‘;
        int n = (int)(Math.random()*999+1);
        if(chengchu==1) 
        {
            switch(n%4)
            {
            case 0:op = ‘+‘;break;
            case 1:op = ‘-‘;break;
            case 2:op = ‘*‘;break;
            case 3:op = ‘/‘;break;
            }
        }
        else
        {
            switch(n%2)
            {
            case 0:op = ‘+‘;break;
            case 1:op = ‘-‘;break;
            }
        }
        return op;
    }
    
    //查重
        public static int chachong(int min,int max,int sumoperate,int chengchu,int zhengquedaan,String str,int sumtitle,int []cishu,int []zqda)
        {
                boolean flag = true;
                if(count==0)
                {
                    arr1[0]=str;
                    return 1;
                }
                else
                {
                    for (int j = 0; j <count; j++) 
                    {
                                if( arr1[count]== arr1[j]) flag = false;
                    }
                    if(flag==true)
                    {
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                }
                
                
        }
        
    //生成随机四则运算
    
    public static void problem(int min,int max,int sumoperate,int chengchu,int sumtitle,String []arr,int []cishu,int []zqda) {
        int a = (int)(Math.random()*(max-min)+min);
        int b = (int)(Math.random()*(max-min)+min);
        char c = operator(chengchu);
        String str = ""+a+c+b;
        int []cunshu = new int[1000];
        char []cunfuhao =new char[1000];
        int shu=0;
        int fuhao=0;
        if(c==‘*‘)
        {
            cunshu[shu]=a*b;
        }
        else if(c==‘/‘)
        {
            cunshu[fuhao]=a/b;
        }
        else
        {
            cunshu[shu]=a;
            shu++;
            cunshu[shu]=b;
            cunfuhao[fuhao]=c;
        }
        
        for(int i=2;i<sumoperate;i++)
        {
            int zenjiashu = (int)(Math.random()*(max-min)+min);
            char zenjiac = operator(chengchu);
            if(zenjiac==‘*‘)
            {
                cunshu[shu]=cunshu[shu]*zenjiashu;
            }
            else if(c==‘/‘)
            {
                cunshu[shu]=cunshu[shu]/zenjiashu;
            }
            else
            {
                shu++;
                cunshu[shu]=zenjiashu;
                fuhao++;
                cunfuhao[fuhao]=zenjiac;
            }    
            str = str + zenjiac + zenjiashu;
        }
        int zhengquedaan=cunshu[0];
        int cou=0;
        for(int j=0;j<=fuhao;j++)
        {
            if(cunfuhao[cou]==‘+‘)
            {
                zhengquedaan+=cunshu[cou+1];
            }
            else
            {
                zhengquedaan-=cunshu[cou+1];
            }
        }
        int panduan=chachong(min,max,sumoperate,chengchu,zhengquedaan,str,sumtitle,cishu,zqda);    
        if(panduan==1)
        {
            arr[ccount]=str;
            zqda[ccount]=zhengquedaan;
            System.out.println(arr[ccount]+"=");
            int daan;
            daan = sc.nextInt(); 
            if(daan!=zhengquedaan)
            {
                cuoticount++;
                cishu[ccount]=1;
            }
            ccount++;
        }
        else
        {
            problem(min,max,sumoperate,sumtitle,chengchu,arr,cishu,zqda);
        }
    }

public static int congzuoma()
{
    System.out.println("是否需要错题重做:(1.是 2.否)");
    int congzuoma;
    congzuoma = sc.nextInt();
    return congzuoma;
}
    
    public static void chongzuo(int sumtitle,String []arr,int []cishu,int []zqda)
    {
        System.out.println("错误率:"+cuoticount/tishusum*100+"%");
        while(true)
        {
            if(congzuoma()==1)
            {
                int cuo=cuoticount;
                cuoticount=0;
                for(int k=0;k<cuo;k++)
                {
                    for(int i=0;i<tishusum;i++)
                    {
                        if(cishu[i]==congzuosum)
                        {
                            System.out.println(arr[i]+"=");
                            int da;
                            da = sc.nextInt(); 
                            if(da!=zqda[i])
                            {
                                
                                System.out.println("正确答案:"+zqda[i]);
                                cishu[i]+=1;
                                cuoticount++;
                            }
                            
                        }
                    }
                    
                }
                congzuosum++;
                System.out.println("错误率:"+cuoticount/sumtitle*100+"%");
            }
            else
            {
                jielun(cishu,arr);
                break;
            }
        }
    }
    
    public static void jielun(int []cishu,String []arr)
    {
        for(int j=0;j<tishusum;j++)
        {
            if(cishu[j]!=0)
            {
                System.out.println(arr[j]+"你错了"+cishu[j]+"次");
            }
        }
    }
    
    public static void main(String[] args) {
        int sumtitle;//出题个数
        int sumoperate;//操作数个数
        int min,max;
        int chengchu;
        System.out.println("请输入出题个数:");
        sumtitle = sc.nextInt();
        System.out.println("请输入操作数个数:");
        sumoperate = sc.nextInt();
        System.out.println("请输入操作数范围:");
        min = sc.nextInt();
        max = sc.nextInt();
        if((max-min)<(2*sumoperate-1)*sumtitle) //系统崩溃条件
        {
            System.out.println("系统崩溃!");
            System.exit(0);
        }
        System.out.println("是否需要乘除运算:1.需要 2.不需要");
        chengchu = sc.nextInt();
        tishusum=sumtitle;
        for(int i=0;i<tishusum;i++)
        {
             problem(min,max,sumoperate,sumtitle,chengchu,arr,cishu,zqda);
        }
        chongzuo(sumtitle,arr,cishu,zqda);
    }
}

 

9.26学习总结

原文:https://www.cnblogs.com/qiuyutingyyds/p/15340051.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!