今天在百忙之中抽出了两个半小时完善了周一的随堂小测,终于完成了王老师的任务。
package org.example; import javafx.util.Pair; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.*; public class Main { static Set<String>set=new HashSet<>();//错题本去重 static Map<String ,Integer>ss=new HashMap<>();//错题的次数 static Map<String,Integer>mp=new HashMap<>();//存对应题目的答案 static List<String>st=new ArrayList<>();//存题目 static int numyes=0,numno=0;//正确个数,错题个数 public static void main(String[] args) { Scanner sc=new Scanner(System.in); boolean flag1=true,flag2=true;//乘除,括号 int k1,ma,mi;//题目个数,最大最小 while(true){ show1();int n=sc.nextInt(); if(n==5)break; if(n==4)index(); if(n==1){ System.out.printf("题目是否有乘除法运算(y/n):"); String c=sc.next(); if(c.equals("y"))flag1=true; else flag1=false; System.out.printf("出题的个数:"); k1=sc.nextInt(); System.out.printf("操作数最大值:"); ma=sc.nextInt(); System.out.printf("操作数最小值:"); mi=sc.nextInt(); ma=100; second(flag1,k1,ma,mi); }else if(n==2){ System.out.printf("题目是否有乘除法运算(y/n):"); String c=sc.next(); if(c.equals("y"))flag1=true; else flag1=false; System.out.printf("出题的个数:"); k1=sc.nextInt(); System.out.printf("操作数最大值:"); ma=sc.nextInt(); System.out.printf("操作数最小值:"); mi=sc.nextInt(); ma=1000; third(flag1,k1,ma,mi); }else if(n==3){ System.out.printf("题目是否有乘除法运算(y/n):"); String c=sc.next(); if(c.equals("y"))flag1=true; else flag1=false; System.out.printf("题目是否有括号(y/n):"); c=sc.next(); if(c.equals("y"))flag2=true; else flag2=false; System.out.printf("出题的个数:"); k1=sc.nextInt(); System.out.printf("操作数最大值:"); ma=sc.nextInt(); System.out.printf("操作数最小值:"); mi=sc.nextInt(); forth(flag1,flag2,k1,ma,mi); } } } public static void show1(){ 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("------------------------------------------------------------"); } public static void show2(){ System.out.println("------------------------------------------------------------"); System.out.println("1、进入下一场答题"); System.out.println("2、查看今日错题"); System.out.println("3、错题二次答题"); System.out.println("------------------------------------------------------------"); } public static int getrandom(int mi,int ma){ Random r=new Random(); int x=mi+r.nextInt(ma-mi+1); return x; } public static char getchar(String s){ Random r=new Random(); int idx=r.nextInt(4); return s.charAt(idx); } public static void second(boolean f1,int k1,int ma,int mi){ System.out.println("设置倒计时时间:"); Scanner sc=new Scanner(System.in); int t=sc.nextInt(); String s; if(f1)s="+-*/"; else s="+-+-"; int cnt=1; int cntno=0; List<Pair<String,Integer>>li=new ArrayList<>(); for(;cnt<=k1;){ int[] a=new int[2]; char c=getchar(s); for(int j=0;j<2;j++) a[j]=getrandom(mi,ma); int ans; if(c=='+')ans=a[0]+a[1]; else if(c=='-')ans=a[0]-a[1]; else if(c=='*')ans=a[0]*a[1]; else{ if(a[1]==0||(a[0]!=0&&a[0]%a[1]!=0))continue; else ans=a[0]/a[1]; } String sk=""+a[0]+c+a[1]; mp.put(sk,ans); Pair<String,Integer>p=new Pair<>(sk,ans); li.add(p); cnt++; } int id=1; long time=System.currentTimeMillis()/1000; for(Pair<String,Integer> p:li){ long cur=System.currentTimeMillis()/1000; if(cur-time>t)break; else System.out.printf("还有%ds\n",t-(cur-time)); System.out.println(""+id+":"+p.getKey()+"=");id++; String sk=p.getKey(); int g=sc.nextInt(),ans=p.getValue(); if(g==ans) {System.out.println("答案正确!");numyes++;cntno++;} else {System.out.printf("答案错误 ------ 正确答案为:%d\n",ans); System.out.println(); numno++; set.add(sk); if(ss.containsKey(sk))ss.put(sk,ss.get(sk)+1); else ss.put(sk,1); } } System.out.printf("错题数为:%d,正确率为:%d\n",k1-cntno,cntno*100/k1); try(PrintWriter wirter=new PrintWriter ("problems1.txt")){ String an=""; int cntc=0; for(Pair<String,Integer> p:li){ cntc++; an+=p.getKey(); an+="="; an+=p.getValue(); an+=" "; wirter.print(an); if(cntc%3==0)wirter.println(); an=""; } } catch (FileNotFoundException e){ e.printStackTrace(); } show2(); int n=sc.nextInt(); if(n==1){ return; }else if(n==2){ index(); }else{ secondtest(); } } public static void third(boolean f1,int k1,int ma,int mi){ String s; if(f1)s="+-*/"; else s="+-+-"; Map<Character,Integer>ap=new HashMap<>(); ap.put('+',1);ap.put('-',1);ap.put('/',2);ap.put('*',2); System.out.println("设置倒计时时间:"); Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int cnt=1,cntyes=0; List<Pair<String,Integer>>li=new ArrayList<>(); for(;cnt<=k1;){ int[] a=new int[4]; boolean fl=true; for(int i=0;i<4;i++) { a[i] = getrandom(mi, ma); if(a[i]<=0)fl=false; } if(!fl)continue; char[] c= new char[3]; for(int i=0;i<3;i++) c[i]=getchar(s); Stack<Integer>stk=new Stack<>(); Stack<Character>stck=new Stack<>(); int ans; String si=""; for(int i=0;i<3;i++){ si+=a[i]; si+=c[i]; }si+=a[3]; int num=0; boolean f=true; for(int i=0;i<si.length();i++){ if(si.charAt(i)<='9'&&si.charAt(i)>='0'){ num=num*10+si.charAt(i)-'0'; }else{ stk.add(num); num=0; if(stck.empty()||ap.get(si.charAt(i))>ap.get(stck.peek()))stck.add(si.charAt(i)); else{ int num2=stk.peek();stk.pop(); int num1=stk.peek();stk.pop(); char ch=stck.peek();stck.pop(); int sum=0; if(ch=='-')sum=num1-num2; else if(ch=='+'){ sum=num1+num2; if(sum>1000){ f=false;break; } }else if(ch=='*'){ sum=num1*num2; if(sum>1000){ f=false;break; } }else{ if(num1%num2!=0){ f=false;break; } sum=num1/num2; } stk.add(sum); while(!stck.empty()&&ap.get(si.charAt(i))<=ap.get(stck.peek())){ num2=stk.peek();stk.pop(); num1=stk.peek();stk.pop(); ch=stck.peek();stck.pop(); sum=0; if(ch=='-')sum=num1-num2; else if(ch=='+'){ sum=num1+num2; }else if(ch=='*'){ sum=num1*num2; }else{ if(num1%num2!=0){ f=false; } sum=num1/num2; } stk.add(sum); } stck.add(si.charAt(i)); } } } if(!f)continue; stk.add(num); while(!stck.empty()){ int num2=stk.peek();stk.pop(); int num1=stk.peek();stk.pop(); char ch=stck.peek();stck.pop(); int sum=0; if(ch=='-'){ sum=num1-num2; } else if(ch=='+'){ sum=num1+num2; if(sum>1000){ f=false;break; } }else if(ch=='*'){ sum=num1*num2; if(sum>10000){ f=false;break; } }else{ if(num1%num2!=0){ f=false;break; } sum=num1/num2; } stk.add(sum); } if(!f)continue; ans=stk.peek(); mp.put(si,ans); Pair<String,Integer>p=new Pair<>(si,ans); li.add(p);cnt++; } int id=1; long time=System.currentTimeMillis()/1000; for(Pair<String,Integer> p:li){ long ti=System.currentTimeMillis()/1000; if(ti-time>t)break; else System.out.printf("还有%ds\n",t-(ti-time)); System.out.println(""+id+":"+p.getKey()+"=");id++; String sk=p.getKey(); int g=sc.nextInt(),ans=p.getValue(); if(g==ans) {System.out.println("答案正确!");numyes++;cntyes++;} else {System.out.printf("答案错误 ------ 正确答案为:%d\n",ans); System.out.println(); numno++; set.add(sk); if(ss.containsKey(sk))ss.put(sk,ss.get(sk)+1); else ss.put(sk,1); } } System.out.printf("错题数为:%d,正确率为:%d\n",k1-cntyes,cntyes*100/k1); try(PrintWriter wirter=new PrintWriter ("problems2.txt")){ String an=""; int cntc=0; for(Pair<String,Integer> p:li){ cntc++; an+=p.getKey(); an+="="; an+=p.getValue(); an+=" "; wirter.print(an); if(cntc%3==0)wirter.println(); an=""; } } catch (FileNotFoundException e){ e.printStackTrace(); } show2(); int n=sc.nextInt(); if(n==1){ return; }else if(n==2){ index(); }else{ secondtest(); } } public static void forth(boolean f1,boolean f2,int k1,int ma,int mi){ String s; if(f1)s="+-*/"; else s="+-+-"; Random r=new Random(); Map<Character,Integer>ap=new HashMap<>(); ap.put('+',1);ap.put('-',1);ap.put('/',2);ap.put('*',2); ap.put('(',3); System.out.println("设置倒计时时间:"); Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int cnt=1,cntyes=0; List<Pair<String,Integer>>li=new ArrayList<>(); int y=0; for(;cnt<=k1;){ int l=getrandom(1,4),lr=getrandom(1,4); if(l>4||l<=0||lr<=0||lr>4||l==lr)continue; int minl=Math.min(l,lr); int maxr=Math.max(l,lr); minl--;maxr--; int[] a=new int[5]; boolean fl=true; for(int i=0;i<5;i++) { a[i] = getrandom(mi,ma); if(a[i]<=0)fl=false; } if(!fl)continue; char[] c= new char[4]; for(int i=0;i<4;i++) c[i]=getchar(s); Stack<Integer>stk=new Stack<>(); Stack<Character>stck=new Stack<>(); int ans; String si=""; for(int i=0;i<4;i++){ if(i==minl)si+="("; si+=a[i]; if(i==maxr)si+=")"; si+=c[i]; }si+=a[4]; int num=0; boolean f=true; //790+(2731/3714*2435)-4446 for(int i=0;i<si.length();i++){ if(si.charAt(i)<='9'&&si.charAt(i)>='0'){ num=num*10+si.charAt(i)-'0'; }else{ if(num!=0)stk.add(num); num=0; if(si.charAt(i)==')'){ while(stck.peek()!='('){ if(stk.size()<2){ f=false;break; } int num2=stk.peek();stk.pop(); int num1=stk.peek();stk.pop(); char ch=stck.peek();stck.pop(); int sum=0; if(ch=='-'){ sum=num1-num2; } else if(ch=='+'){ sum=num1+num2; }else if(ch=='*'){ sum=num1*num2; }else{ if(num1%num2!=0){ f=false; } sum=num1/num2; } stk.add(sum); } if(!f)break; stck.pop(); } else { if (stck.empty() || ap.get(si.charAt(i)) > ap.get(stck.peek())){ stck.add(si.charAt(i)); if(si.charAt(i)=='(')ap.put('(',0); } else { if(stk.size()<2){ f=false;break; } int num2=stk.peek();stk.pop(); int num1=stk.peek();stk.pop(); char ch=stck.peek();stck.pop(); int sum=0; if(ch=='-')sum=num1-num2; else if(ch=='+'){ sum=num1+num2; }else if(ch=='*'){ sum=num1*num2; }else{ if(num1%num2!=0){ f=false; } sum=num1/num2; } if(!f)break; stk.add(sum); while(!stck.empty()&&ap.get(si.charAt(i))<=ap.get(stck.peek())){ if(stk.size()<2){ f=false;break; } num2=stk.peek();stk.pop(); num1=stk.peek();stk.pop(); ch=stck.peek();stck.pop(); sum=0; if(ch=='-')sum=num1-num2; else if(ch=='+'){ sum=num1+num2; }else if(ch=='*'){ sum=num1*num2; }else{ if(num1%num2!=0){ f=false; } sum=num1/num2; } stk.add(sum); } if(!f)break; stck.add(si.charAt(i)); } } } } if(!f)continue; stk.add(num); while(!stck.empty()){ if(stk.size()<2){ f=false;break; } int num2=stk.peek();stk.pop(); int num1=stk.peek();stk.pop(); char ch=stck.peek();stck.pop(); int sum=0; if(ch=='-'){ sum=num1-num2; } else if(ch=='+'){ sum=num1+num2; }else if(ch=='*'){ sum=num1*num2; }else{ if(num1%num2!=0){ f=false; } sum=num1/num2; } stk.add(sum); } if(!f)continue; ans=stk.peek(); mp.put(si,ans); Pair<String,Integer>p=new Pair<>(si,ans); li.add(p); cnt++; } int id=1; long time=System.currentTimeMillis()/1000; for(Pair<String,Integer> p:li){ long ti=System.currentTimeMillis()/1000; if(ti-time>t)break; else System.out.printf("还有%ds\n",t-(ti-time)); System.out.println(""+id+":"+p.getKey()+"=");id++; String sk=p.getKey(); int g=sc.nextInt(),ans=p.getValue(); if(g==ans) {System.out.println("答案正确!");numyes++;cntyes++;} else {System.out.printf("答案错误 ------ 正确答案为:%d\n",ans); System.out.println(); numno++; set.add(sk); if(ss.containsKey(sk))ss.put(sk,ss.get(sk)+1); else ss.put(sk,1); } } System.out.printf("错题数为:%d,正确率为:%d\n",k1-cntyes,cntyes*100/k1); try(PrintWriter wirter=new PrintWriter ("problems3.txt")){ String an=""; int cntc=0; for(Pair<String,Integer> p:li){ cntc++; an+=p.getKey(); an+="="; an+=p.getValue(); an+=" "; wirter.print(an); if(cntc%3==0)wirter.println(); an=""; } } catch (FileNotFoundException e){ e.printStackTrace(); } show2(); int n=sc.nextInt(); if(n==1){ return; }else if(n==2){ index(); }else{ secondtest(); } } public static void index(){ Scanner sc=new Scanner(System.in); int k=1; for(String sy:set){ System.out.printf("%d:%s= 错题次数为%d\n",k++,sy,ss.get(sy)); } System.out.printf("错题数:%d,正确率:%d\n",numno,numyes/(numno+numyes)); System.out.println("是否进行二次做题(y/n)"); String s=sc.next(); if(s.equals("y"))secondtest(); } public static void secondtest(){ int k=1; Scanner sc=new Scanner(System.in); for(String sy:set){ System.out.printf("%d:%s=",k++,sy); int ans=sc.nextInt(); if(ans==mp.get(sy)){ System.out.println("回答正确!"); }else{ System.out.printf("答案错误!---- 答案为:%d\n",mp.get(sy)); ss.put(sy,ss.get(sy)+1); } } } }
标签:int,9.29,System,else,sc,new,out From: https://www.cnblogs.com/binglinll/p/17736976.html