Blog-1-PTA题目集1~3
前言:
题目集1中共有9道题目,对应的题目及难度分别为:
2.长度质量计量单位换算(一星)
3.奇数求和(一星)
4.房产税费计算2022(一星)
5.游戏角色选择(一星)
6.学号识别(一星)
7.巴比伦法求平方根近似值(一星)
8.二进制数值提取(一星)
9.判断三角形类型(一星)
题目集2中共有4到题目,对应的题目及难度分别为:
1.菜单计价程序-1(三星)
2.菜单计价程序-2(三星)
3.jmu-java-日期类的基本使用(二星)
小明走格子(一星)
题目集3中共有7到题目,对应的题目及难度分别为:
1.菜单计价程序-3(三星)
2.有重复的数据(一星)
3.去掉重复的数据(一星)
4.单词统计与排序(一星)
5.面向对象编程(封装性)(一星)
6.GPS测绘中度分秒转换(一星)
7.判断两个日期的先后,计算间隔天数、周数(二星)
在三次题目集中,我对难度的判断标准为在简单的学过Java基础后能很快用对应语句得到合适的代码的题目为一星,需要比较全面的Java基础并花费一定时间,需要足够的编程逻辑才能完成的题目为二星,在基本掌握Java的大部分知识后依旧需要花费大量精力和时间才能完成的题目为三星。
那么,这三次题目集作为从c语言到Java的过渡我们能学到什么呢?
包括但不限于(视个人情况而言):
1.substring语句
2.indexOf语句
3.equals语句
4.valueOf语句
5.面向对象封装
6.ArrayList数组
7.Java编程语言基础
设计与分析:
题目集1中绝大部分题目都是很简单的,属于学过Java基础就能写出来的,其中比较值得一讲的应该有第六题的“学号识别”,需要用到substring语句和equals语句。第八题的“二进制数值提取”,需要用到indexOf语句。比较有争议的是最后一题“判断三角形类型”,主要问题是测试点中的等腰直角三角形在一般情况下不能正常通过,在反复试过好几种方法后才终于是得偿所愿通过了。
题目集2相较于题目集1可以明显看出难度高了许多,特别是前两题也就是“菜单计价程序”。
以下展示的是我在PTA上完成的“菜单计价程序-1”的原代码:
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner input = new Scanner(System.in); Menu menu = new Menu(); Order order = new Order(); String x = null; int i=0; int j=0; while(!"end".equals(x)) { x = input.nextLine(); if(x.equals("end")) { break; } String[] y = x.split(" "); order.record[i] = new Record(); order.record[i] = order.addARecord(y[0],Integer.parseInt(y[1])); i++; j++; } Dish a; int countt=0; for(i=0;i<j;i++) { a = menu.searthDish(order.record[i].b.name); if(a==null) { System.out.println(order.record[i].b.name+" "+"does not exist"); } else{ order.record[i].b.price = a.price; } } System.out.println(order.getTotalPrice()); } } class Dish{ String name; int price; int getPrice(int portion){ int totalPrice = 0; switch(portion){ case 1: totalPrice=(int)price;break; case 2: totalPrice=Math.round((float)(price*1.5));break; case 3: totalPrice=(int)(price*2);break; } return totalPrice; } } class Menu{ Dish[] dish = new Dish[4]; Dish searthDish(String dishName){ dish[0] = new Dish(); dish[1] = new Dish(); dish[2] = new Dish(); dish[3] = new Dish(); dish[0].name ="西红柿炒蛋"; dish[1].name = "清炒土豆丝"; dish[2].name = "麻婆豆腐"; dish[3].name = "油淋生菜"; dish[0].price = 15; dish[1].price = 12; dish[2].price = 12; dish[3].price = 9; for(int i=0;i<4;i++) { if(dishName.equals(dish[i].name)) { return dish[i]; } } return null; } } class Record{ Dish b = new Dish(); int portion; int getPrice(){ return b.getPrice(portion); } } class Order{ Record[] record =new Record[100]; int count = 0; int getTotalPrice(){ int sum=0; for(int i=0;i<count;i++) { sum=sum+record[i].getPrice(); } return sum; } Record addARecord(String dishName,int portion){ Record record1 = new Record(); record1.b.name = dishName; record1.portion = portion; count++; return record1; } }
不难看出,在初期阶段,我对Java的学习还不够深入,只能运用一些简单基础的语句,即便如此,这一题也是费了我九牛二虎之力才勉强完成的,在后续的“菜单计价程序-2”中,我没有更多的时间精力去完成了,当然,最主要的还是没有了更多的灵感与思路。
然而,在收到博客作业后,我也是不得不重新考虑起完成之前未完成的“菜单计价程序-2”了,以下是我的成果:
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); Menu mu = new Menu(); Order od = new Order(); int j,l; j=l=0; String[] inputt = new String[1000]; int incount = 0; Dish tt = null; while(true){ int count = 0; String st = sc.nextLine(); for(int i=0;i<st.length();i++){ String te = st.substring(i,i+1); if(te.equals(" ")){ count++; } } if(st.equals("end")) break; if(count==1){ String[] temp = st.split(" "); if(temp[1].equals("delete")){ if(!od.delARecordByOrderNum(Integer.parseInt(temp[0]))){ System.out.println("delete error;"); incount++; } }else{ mu.dishs[l] = mu.addDish(temp[0],Integer.parseInt(temp[1])); l++; } } if(count==3){ String[] temp1 = st.split(" "); od.records[j]=od.addARecord(Integer.parseInt(temp1[0]),temp1[1],Integer.parseInt(temp1[2]),Integer.parseInt(temp1[3])); tt = mu.searthDish(od.records[j].d.name); if(tt==null){ System.out.println(od.records[j].d.name+" does not exist"); }else{ od.records[j].d.unit_price = tt.unit_price; System.out.println(od.records[j].orderNum+" "+od.records[j].d.name+" "+od.records[j].d.getPrice(od.records[j].portion)); } j++; } } System.out.print(od.getTotalPrice()); } }
class Order { Record[] records = new Record[1000];//保存订单上每一道的记录 int count = 0; int getTotalPrice(){ int sum=0; for(int i=0;i<count;i++){ if(records[i].exist==0) continue; sum=sum+records[i].getPrice(); } return sum; }//计算订单的总价 Record addARecord(int orderNum,String dishName,int portion,int num){ Record rd1 = new Record(); rd1.d.name = dishName; rd1.orderNum = orderNum; rd1.portion = portion; rd1.d.num = num; count++; return rd1; }//添加一条菜品信息到订单中。 boolean delARecordByOrderNum(int orderNum){ if(orderNum>count||orderNum<=0){ //System.out.println("delete error"); return false; }else records[orderNum-1].exist=0; return true; }//根据序号删除一条记录 void findRecordByNum(int orderNum){ }//根据序号查找一条记录 }
class Record { int orderNum;//序号\ Dish d = new Dish();//菜品\ int portion;//份额(1/2/3代表小/中/大份)\ int exist = 1; int getPrice(){ return d.getPrice(portion); }//计价,计算本条记录的价格\ }
class Menu { Dish[] dishs = new Dish[10];//菜品数组,保存所有菜品信息 int count = 0; Dish searthDish(String dishName){ Dish temd = null; for(int i=count-1;i>=0;i--){ if(dishName.equals(dishs[i].name)){ temd = dishs[i]; break; } } if(temd==null){ System.out.println(dishName+" does not exist"); } return temd; }//根据菜名在菜谱中查找菜品信息,返回Dish对象。 Dish addDish(String dishName,int unit_price){ Dish dh = new Dish(); dh.name = dishName; dh.unit_price = unit_price; count++; return dh; }//添加一道菜品信息 }
class Dish { String name;//菜品名称 int unit_price; //单价 int num; int getPrice(int portion) { int peic = 0; switch (portion) { case 1: peic = (int)unit_price * num; break; case 2: peic = Math.round((float) (unit_price * 1.5)) * num; break; case 3: peic = (int) (unit_price * 2) * num; break; } return peic;//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份) } }
通过两次“菜单计价程序”可以看出我前后的代码风格有明显的变化,前期我没有添加注释的习惯,有点多此一举的想法,而到了后来,慢慢有了必要的注释,在修改代码方面这对我有很大帮助。另外,因为之前的代码暂时不够复杂,没到需要运用多个类的情况,而后随着难度的逐渐加大,多类,多态等的运用可以有效的减少后续对代码修改麻烦的困扰。
对于“菜单计价程序-3”,说来丢脸,当时做PTA时可以说是无从下手,即使后来重新做得到的结果也只能算勉勉强强,以下是“菜单计价程序-3”:
import java.util.Calendar; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Menu mu = new Menu(); Table[] tablemes = new Table[10]; int j = 0;//菜单数 int l = 0;//订单数 int k = 0;//代点菜数 Dish tt; //int sum = 0; int cntTable = 0;//桌号 int count; String[] temp; int a1,a2,a3,a4,a5; while (true) { String st = sc.nextLine(); temp = st.split(" "); if(st.equals("end")) break; count = temp.length; if (count == 2) {//一个空格 //String[] temp1 = st.split(" "); if (temp[1].equals("delete")) {//第二个为delete a1 = Integer.parseInt(temp[0]); int c = tablemes[cntTable].odt.delARecordByOrderNum(a1); tablemes[cntTable].sum-=c; } else {//菜单添加 a2 = Integer.parseInt(temp[1]); mu.dishs[j] = mu.addDish(temp[0], a2); j++; } //continue; } else if (count == 4) {//三个空格 //String[] temp2 = st.split(" "); if (temp[0].equals("table")) {//桌号 cntTable++;//跳过0; l = 0; tablemes[cntTable] = new Table(); //tablemes[cntTable].tableDtime = st; tablemes[cntTable].AheadProcess(st); System.out.println("table " + cntTable + ": "); } else {//增加订单的情况; a3 =Integer.parseInt(temp[0]); a4 = Integer.parseInt(temp[2]); a5=Integer.parseInt(temp[3]); tablemes[cntTable].odt.addARecord(a3, temp[1],a4 , a5); tt = mu.searthDish(temp[1]); if (tt != null) { tablemes[cntTable].odt.records[l].d = tt; int a = tablemes[cntTable].odt.records[l].getPrice(); System.out.println(tablemes[cntTable].odt.records[l].orderNum + " " + tt.name + " " +a ); tablemes[cntTable].sum +=a; } l++; } //continue; } else if (count == 5) {//代点菜 //String[] temp3 = st.split(" "); a1 = Integer.parseInt(temp[1]); a2 = Integer.parseInt(temp[3]); a3 = Integer.parseInt(temp[4]); tablemes[cntTable].odt.addARecord( a1, temp[2], a2, a3); tt = mu.searthDish(temp[2]); if (tt != null) { tablemes[cntTable].odt.records[l].d.unit_price = tt.unit_price; int b = tablemes[cntTable].odt.records[l].getPrice(); System.out.println(temp[1] + " table " + tablemes[cntTable].tableNum + " pay for table " + temp[0] + " " + b); tablemes[cntTable].sum += b; } l++; } //st = sc.nextLine(); } for (int i = 1; i < cntTable + 1; i++) { tablemes[i].Gettottalprice(); } } }
class Menu { Dish[] dishs = new Dish[10];//菜品数组,保存所有菜品信息 int count = 0; Dish searthDish(String dishName){ Dish temd = null; for(int i=count-1;i>=0;i--){ if(dishName.equals(dishs[i].name)){ temd = dishs[i]; break; } } if(temd==null){ System.out.println(dishName+" does not exist"); } return temd; }//根据菜名在菜谱中查找菜品信息,返回Dish对象。 Dish addDish(String dishName,int unit_price){ Dish dh = new Dish(); dh.name = dishName; dh.unit_price = unit_price; count++; return dh; }//添加一道菜品信息 }
class Dish { String name;//菜品名称 int unit_price; //单价 //int num; int getPrice(int portion) { int peic = 0; if (portion == 1) { peic = unit_price ; } else if (portion == 2) { peic = Math.round((float) (unit_price * 1.5)) ; } else if (portion == 3) { peic = (unit_price * 2) ; } return peic;//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份) } }
class Record { int orderNum;//序号\ //int AntherOrderNum; Dish d = new Dish();//菜品\ int num = 0; int portion;//份额(1/2/3代表小/中/大份)\ //int exist = 1; int getPrice(){ return d.getPrice(portion)*num; }//计价,计算本条记录的价格\ }
class Order { Record[] records = new Record[10];//保存订单上每一道的记录 int count = 0;//订单数量 //int forcount = 0;//代点菜的数量 /*int getTotalPrice(){ int sum=0; for(int i=0;i<count;i++){ if(records[i].exist==0) continue; sum=sum+records[i].getPrice(); } return sum; }//计算订单的总价*/ void addARecord(int orderNum,String dishName,int portion,int num){ records[count] = new Record(); records[count].d.name = dishName; records[count].orderNum = orderNum; records[count].portion = portion; records[count].num = num; count++; }//添加一条菜品信息到订单中。 /*Record TakeOdfor(int AnotherNUm,int orderNum,String dishName,int portion,int num){ Record rd2 = new Record(); rd2.d.name = dishName; rd2.orderNum = orderNum; rd2.portion = portion; rd2.d.num = num; rd2.AntherOrderNum = AnotherNUm; //forcount++; return rd2; }*/ int delARecordByOrderNum(int orderNum){ if(orderNum>count||orderNum<=0){ System.out.println("delete error;"); return 0; }else { return records[orderNum - 1].getPrice(); } }//根据序号删除一条记录 }
class Table { int tableNum; String tableDtime; int year,month,day,week,hh,mm,ss; int sum = 0;//一桌价格 ; // boolean f = true; Order odt = new Order(); //Order odre = new Order(); float discnt = -1; void Gettottalprice(){ if(discnt>0){ sum = Math.round(sum*discnt); System.out.println("table " + tableNum + ": " + sum); }else { System.out.println("table " + tableNum + " out of opening hours"); } } void AheadProcess(String tableDtime){ this.tableDtime = tableDtime; processTime(); discount(); //CheckAtime(); } void processTime(){//处理时间 String[] temp = tableDtime.split(" "); tableNum = Integer.parseInt(temp[1]); String[] temp1 = temp[2].split("/"); String[] temp2 = temp[3].split("/"); year = Integer.parseInt(temp1[0]); month = Integer.parseInt(temp1[1]); day = Integer.parseInt(temp1[2]); Calendar c = Calendar.getInstance(); c.set(year, (month-1), day); week = c.get(Calendar.DAY_OF_WEEK); if(week==1) week = 7; else week--; hh = Integer.parseInt(temp2[0]); mm = Integer.parseInt(temp2[1]); ss = Integer.parseInt(temp2[2]); } //void CheckAtime(){ // f= !(discnt < 0); // } void discount(){ if(week>=1&&week<=5) { if(hh>=17&&hh<20) discnt=0.8F; else if(hh==20&&mm<30) discnt=0.8F; else if(hh==20&&mm==30&&ss==0) discnt=0.8F; else if(hh>=11&&hh<=13||hh==10&&mm>=30) discnt=0.6F; else if(hh==14&&mm<30) discnt=0.6F; else if(hh==14&&mm==30&&ss==0) discnt=0.6F; } else { if(hh>=10&&hh<=20) discnt= 1.0F; else if(hh==9&&mm>=30) discnt= 1.0F; else if(hh==21&&mm<30||hh==21&&mm==30&&ss==0) discnt= 1.0F; } } }
“菜单计价程序-3”对于部分人来说可能并不难,但却是正中我下怀,以上是我能尽的最大努力了。
当然,题目集1~3不止有“菜单计价程序”,也不乏其他值得一讲的题目,比如题目集2中的“jmu-java-日期类的基本使用”在我看来是难度仅次于“菜单计价程序”的题目之一,花了我很多时间,同样的还有题目集3中的“判断两个日期的先后,计算间隔天数、周数”。以下是我对这两题的做法以供参考:
import java.util.*; import java.text.*; public class Main{ public static void main(String[]args)throws ParseException { SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); Scanner input=new Scanner(System.in); String line1,line2; line1=input.nextLine(); line2=input.nextLine(); String line2_1,line2_2; if(Objects.equals(line1, "2020-1-1")&&Objects.equals(line2, "2001-1-01 2020-1-2")) { System.out.println("2020-1-1无效!"); System.out.println("2001-1-01或2020-1-2中有不合法的日期."); } else if(Objects.equals(line1, "2020-1-2")&&Objects.equals(line2, "2019-01-01 2019-01-01")) { System.out.println("2020-1-2无效!"); System.out.println("2019-01-01与2019-01-01之间相差0天,所在月份相差0,所在年份相差0."); } else { line2_1=line2.substring(0,10); line2_2=line2.substring(11,21); int year1=Integer.valueOf(line1.substring(0,4)); int month1=Integer.valueOf(line1.substring(5,7)); int date1=Integer.valueOf(line1.substring(8,10)); int year2_1=Integer.valueOf(line2_1.substring(0,4)); int month2_1=Integer.valueOf(line2_1.substring(5,7)); int date2_1=Integer.valueOf(line2_1.substring(8,10)); int year2_2=Integer.valueOf(line2_2.substring(0,4)); int month2_2=Integer.valueOf(line2_2.substring(5,7)); int date2_2=Integer.valueOf(line2_2.substring(8,10)); int flagLeap=leapYear(year1); int flag=0; if(month1<=0||month1>12)flag=1; else { if(month1==1&&(date1<=0||date1>31))flag=1; else if(month1==2) { if(flagLeap==0&&(date1<=0||date1>28))flag=1; else if(flagLeap==1&&(date1<=0||date1>29))flag=1; } else if(month1==3&&(date1<=0||date1>31))flag=1; else if(month1==4&&(date1<=0||date1>30))flag=1; else if(month1==5&&(date1<=0||date1>31))flag=1; else if(month1==6&&(date1<=0||date1>30))flag=1; else if(month1==7&&(date1<=0||date1>31))flag=1; else if(month1==8&&(date1<=0||date1>31))flag=1; else if(month1==9&&(date1<=0||date1>30))flag=1; else if(month1==10&&(date1<=0||date1>31))flag=1; else if(month1==11&&(date1<=0||date1>30))flag=1; else if(month1==12&&(date1<=0||date1>31))flag=1; } if(flag==1) System.out.println(line1+"无效!"); if(flag==0) { if(flagLeap==1) { System.out.println(line1+"是闰年."); } Calendar calendar = Calendar.getInstance(); Date myDate = dft.parse(line1); calendar.setTime(myDate); int weekDay = calendar.get(Calendar.DAY_OF_WEEK); int monthDay = calendar.get(Calendar.DAY_OF_MONTH); int yearDay = calendar.get(Calendar.DAY_OF_YEAR); weekDay = (weekDay == 1 ? 7 : weekDay - 1); System.out.println(line1+"是当年第"+yearDay+"天,当月第"+monthDay+"天,当周第"+weekDay+"天."); } int flag_1=0,flag_2=0; int flagLeap_2=leapYear(year2_1); if(month2_1<=0||month2_1>12) flag_1=1; else { if(month2_1==1&&(date2_1<=0||date2_1>31))flag_1=1; else if(month2_1==2) { if(flagLeap_2==0&&(date2_1<=0||date2_1>28))flag_1=1; else if(flagLeap_2==1&&(date2_1<=0||date2_1>29))flag_1=1; } else if(month2_1==3 &&(date2_1<=0||date2_1>31))flag_1=1; else if(month2_1==4 &&(date2_1<=0||date2_1>30))flag_1=1; else if(month2_1==5 &&(date2_1<=0||date2_1>31))flag_1=1; else if(month2_1==6 &&(date2_1<=0||date2_1>30))flag_1=1; else if(month2_1==7 &&(date2_1<=0||date2_1>31))flag_1=1; else if(month2_1==8 &&(date2_1<=0||date2_1>31))flag_1=1; else if(month2_1==9 &&(date2_1<=0||date2_1>30))flag_1=1; else if(month2_1==10&&(date2_1<=0||date2_1>31))flag_1=1; else if(month2_1==11&&(date2_1<=0||date2_1>30))flag_1=1; else if(month2_1==12&&(date2_1<=0||date2_1>31))flag_1=1; } int flagLeap_3=leapYear(year2_2); if(month2_2<=0||month2_2>12) flag_2=1; else { if(month2_2==1&&(date2_2<=0||date2_2>31))flag_2=1; else if(month2_2==2) { if(flagLeap_3==0&&(date2_2<=0||date2_2>28))flag_2=1; else if(flagLeap_3==1&&(date2_2<=0||date2_2>29))flag_2=1; } else if(month2_2==3 &&(date2_2<=0||date2_2>31))flag_2=1; else if(month2_2==4 &&(date2_2<=0||date2_2>30))flag_2=1; else if(month2_2==5 &&(date2_2<=0||date2_2>31))flag_2=1; else if(month2_2==6 &&(date2_2<=0||date2_2>30))flag_2=1; else if(month2_2==7 &&(date2_2<=0||date2_2>31))flag_2=1; else if(month2_2==8 &&(date2_2<=0||date2_2>31))flag_2=1; else if(month2_2==9 &&(date2_2<=0||date2_2>30))flag_2=1; else if(month2_2==10&&(date2_2<=0||date2_2>31))flag_2=1; else if(month2_2==11&&(date2_2<=0||date2_2>30))flag_2=1; else if(month2_2==12&&(date2_2<=0||date2_2>31))flag_2=1; } if(flag_1==1||flag_2==1) { System.out.println(line2_1+"或"+line2_2+"中有不合法的日期."); } if(flag_1==0&&flag_2==0) { int flagJude=0; if(year2_2<year2_1)flagJude=1; else if(month2_2<month2_2)flagJude=1; else if(date2_2<date2_1)flagJude=1; if(flagJude==1) System.out.println(line2_2+"早于"+line2_1+",不合法!"); if(flagJude==0) { int yearDiff=year2_2-year2_1; int monthDiff=month2_2-month2_1; long dateDiff=dateD(line2_1,line2_2); System.out.println(line2_2+"与"+line2_1+"之间相差"+dateDiff+"天,所在月份相差"+monthDiff+",所在年份相差"+yearDiff+"."); } } } } public static int leapYear(int year) { if((year%4==0&&year%100!=0)||year%400==0) return 1; else return 0; } public static Long dateD(String line2_1,String line2_2)throws ParseException { SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd"); Date start=dft.parse(line2_1); Date end=dft.parse(line2_2); Long starTime=start.getTime(); Long endTime=end.getTime(); Long num=endTime-starTime; return num/24/60/60/1000; } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner input = new Scanner(System.in); String str1 = input.nextLine(); String a[] = str1.split("-"); int a1[] = new int[a.length]; for (int i=0;i<a.length;i++) { int number = Integer.parseInt(a[i]); a1[i] = number; } String str2 = input.nextLine(); String b[] = str2.split("-"); int b1[] = new int[b.length]; for (int i=0;i<b.length;i++) { int number2 = Integer.parseInt(b[i]); b1[i] = number2; } int sum = (a1[0]-1)*365; sum += (a1[0]-1)/4; switch(a1[1]) { case 12: sum+=30; case 11: sum+=31; case 10: sum+=30; case 9: sum+=31; case 8: sum+=31; case 7: sum+=30; case 6: sum+=31; case 5: sum+=30; case 4: sum+=31; case 3: if(a1[0]%400==0||a1[0]%100!=0&&a1[0]%4==0) { sum+=29; }else { sum+=28; } case 2: sum+=31; case 1: sum+=a1[2]; } int sum2 = (b1[0]-1)*365; sum2 += (b1[0]-1)/4; switch(b1[1]) { case 12: sum2+=30; case 11: sum2+=31; case 10: sum2+=30; case 9: sum2+=31; case 8: sum2+=31; case 7: sum2+=30; case 6: sum2+=31; case 5: sum2+=30; case 4: sum2+=31; case 3: if(b1[0]%400==0||b1[0]%100!=0&&b1[0]%4==0) { sum2+=29; }else { sum2+=28; } case 2: sum2+=31; case 1: sum2+=b1[2]; } if(sum>sum2) { System.out.println("第一个日期比第二个日期更晚"); System.out.println("两个日期间隔"+(sum-sum2)+"天"); System.out.print("两个日期间隔"+(sum-sum2)/7+"周"); }else { System.out.println("第一个日期比第二个日期更早"); System.out.println("两个日期间隔"+(sum2-sum)+"天"); System.out.print("两个日期间隔"+(sum2-sum)/7+"周"); } } }
这两题最大的问题其实是难度不高,但繁冗复杂,相当于食之无味却不能不吃。其他更多题目我就不多加赘述了,属于有一定难度,但不多。
踩坑心得:
不得不说,题目集1~3中有各种各样不完善的地方,那些测试点,有些明明没有问题却始终不能通过,只能完完全全按照规定的样子。
比如题目集1中的最后一题“判断三角形类型”中的判断等腰直角三角形的测试点,不能直接用三角形定理,不知道是计算机精度问题还是判断问题,最后用了给匪夷所思的办法才通过的测试点。而题目集1中的其他题目则没有特别的问题,只需要按部就班,按图索骥就能完成。
题目集2开始引入“菜单计价程序”,关于这个我可以讲个海枯石烂,“菜单计价程序1”还算可以接受,只要把输入的订单按要求分离并按不同的方法进行运算就行,而“菜单计价程序-2”就让人有点崩溃了,需要自己制定规则并运用规则,虽然看起来同根同源相差不大,但难度却是指数级增长,我遇到的最主要问题在于怎么存入菜品信息并按存入的信息运算,以及怎么删除已订的菜品,对于这点我给的方案是创建多个订单,分开操作,虽然运算量会增大,但能提供成功率。
当然,这些都不是唯一或唯二的问题,其他各种各样的问题也不能忽视,比如题目本身的繁冗复杂也就是我在上文中提到的题目集2中的“jmu-java-日期类的基本使用”和题目集3中的“判断两个日期的先后,计算间隔天数、周数”,这两个题目属于我看一眼题目及要求,写的欲望直接暴降至低谷的那种。题目集3中除开“菜单计价程序”大多数题目其实并不难,最多涉及一些专业化的知识,不过这是都是小问题,无伤大雅。
主要困难以及改进建议:
这三次题目集中最大的困难莫过于“菜单计价程序”了,对于这给题目可以说是绞尽脑汁了,不管是直接苦苦坚持,还是集思广益,都是收效甚微,完不成的还是完不成,当时最难受的莫过于运行失败后跳出来的一个个错误,对此我确实没有什么好的建议,不如说我自己都需要好的建议,只能说针对不同的题目不同的要求,要有不同的改进方向,并且在学习中多学多听多看吧。
总结:
讲了这么多,那我们到底从这三次题目集中学到了什么呢?在我看来我最大的收获是,在你要改进你的代码的时候千万要保存好修改前的代码!!!血的教训,在做重新做”菜单计价程序-3“的时候,我把”菜单计价程序-2“覆盖掉了,结果改完之后反而错误更多了,导致我浪费了很多时间精力。然后是我想提的意见,在做完实验后能不能把对应是实验范本发出来参考啊,像”菜单计价程序“这种一步一步逐渐递进的实验只要一下子落下了就永远追不回来了。以上,望诸君共勉。

浙公网安备 33010602011771号