晚风于我皆客总结性Blog-2
前言:第一次作业的第一题学习到了身体质量指数的计算方法且质量指数在什么范围内有什么情况(即学会如何用if函数),而且学习到了题目的严格要求代码也得遵守,小细节都不行。第一题的难度不是很大,题量不大。第一次作业的第二题首先学习到了1磅和1英寸的国际单位制与英制之间的计算的换算,其次题目要求用浮点数,浮点数有两种表示方式,一种是float,一种是double,在这道题中,若是zhi,chang两个变量全部用double,结果会出错,而且剩余变量也是,我觉得是因为内存的问题和精度的问题,学习到了什么时候用double,什么时候用float,题量不大,也不难,第三题奇数求和学习到了用数组,题量和难度是最低的,第四题学习到了怎么输出空格形式以及浮点数的应用,题量不多,难度一开始觉得挺难,是因为看不懂题,后来就觉得不难了。第五题是游戏角色选择,我学习到了Switch和case的用法,题量少,题目简单,第六题学到了用字符来描述问题解决问题,并且学到如何计算每一位的数字,题量比较麻烦,难度有点大,对于当时来说,第七题学到在浮点数中比较大小精确度在0.01之内而且学到如何将三角形划分几类三角形,难度偏中,题量较大,第八题学到了用巴比伦法求平方根近似值,不能将浮点数写成double,因为float精确到前几位,而double不是,学会用循环,难度较低,题量较小,第九题学会了如何访问字符串的字符,难度适中,题量不多。
第二次作业的第一题我学会了运用古典变量来对情况进行分析,难度较小,题量较小
。第二题学会了用一个正则表达式判断输入是否合法以及循环逻辑的结构梳理,难度较大,题量适中。第三题学习到了如何表示一串字符中以n个一维数组分隔开来完成题目,以及循环结构,难度较大,题量不大。
第三次作业的第一题我学会了如何用正则表达式判断一个字符串是否为double类型,以及如何以,将字符内容分隔开和怎么以空格将点坐标分隔开,难度较大,题量较大。第二题学习到了用Switch和case对情况进行甄选,以及跟第一题一样的收获。第三题学会了如何用正则表达式判断一个字符串是否为double类型,以及如何以,将字符内容分隔开和怎么以空格将点坐标分隔开,用Switch和case对情况进行甄选,以及三角形和直线的位置关系,判断三角形是不是直角还是钝角还是锐角难度特大,题量特大。
第四次作业的第一题我学会了如何提取字符串中除了特定字符的剩余字符串用数字表示,如何使用一个字符串是否与给定的字符串一致,难度很小,题量很小。第二题我学会了如何判定是否为四边形和平行四边形,以及正方形,菱形和矩形,如何判断是凸四边形还是凹四边形,也学会了怎么判断double类型的数有几位小数,以及四舍五入指定位数,难度很大,题量很大。第三题我学会了如何使用多个类并且如何封装属性,理解了类与对象之间的关系,学会调用对象。难度适中,题量不大。
期中考试的第一题学会了怎么将数值保留几位小数,以及使用多个类并且如何封装属性,理解了类与对象和类与类之间的关系,学会调用对象,还学会了如何调用类中的私有属性,必须通过该类的构造函数的获得来得到该属性。难度适中,题量不大。第二题学会了怎么将数值保留几位小数,以及使用多个类并且如何封装属性,理解了类与对象和类与类之间的关系,以及怎么使用父类和父类与子类的关系(即继承关系),学会在父类写什么东西,学会调用对象,还学会了如何调用类中的私有属性,必须通过该类的构造函数的获得来得到该属性。难度适中,题量较多。第三题学会了怎么将数值保留几位小数,以及使用多个类并且如何封装属性,理解了类与对象和类与类之间的关系,以及怎么使用父类和父类与子类的关系(即继承关系),学会在父类写什么东西,学会调用对象,学会了如何使用容器保存类的对象以及进行相应的增删遍历操作还学会了如何调用类中的私有属性,必须通过该类的构造函数的获得来得到该属性。难度较大,题量较多。
第五次作业第一题学会了如何用正则表达式判断一个字符串是否为double类型,以及如何以,将字符内容分隔开和怎么以空格将点坐标分隔开,用Switch和case对情况进行甄选,学会了如何判断是否为五边形以及凹凸五边形,如何判断直线与五边形的位置关系。难度很大,题量很多。第二题学会了如何用正则表达式判断一个字符串是否为double类型,以及如何以,将字符内容分隔开和怎么以空格将点坐标分隔开,也学会了怎么判断double类型的数有几位小数,以及四舍五入指定位数,学会了如何输入五个点判断是否构成三角形和四边形和五边形以及怎么判断凹凸多变形,学会了如何判断直线与多边形的位置关系和多边形与多边形的位置关系,以及公共区域的面积,难度特别大,题量也很大。
设计与分析:第一次作业的第一题我的思路是先定义两个输入的浮点型变量sg,tz,以及定义浮点型变量BMI进行赋值BMI = tz/(sg*sg),然后根据BMI的取值范围分别对应其操作。
第二题我的思路是定义个输入的浮点型变量zhi,chang,并且将 0.45359237和0.0254赋值给两个变量,然后再做运算输出结果。第三题我的思路是创建一个放置10个元素的数组,然后用for循环对每个元素进行输入以存储在数组中并且执行判断为奇数的操作,最终输出奇数之和。第四题我的思路是定义题目中要求的四个输入变量,然后作为购房次数的那个变量在取值范围内进行讨论,里面在房屋面积的那个变量进行讨论执行相应操作,在循环外再列式子最终将其输出。第五题我的思路是定义两个输入的整数型变量,分别对变量进行Switch case语句实行对应输出的结果。第六题我的思路定义一个可以输入一行的输入变量,先判断位数,如果不是8位,非法输入,如果是8位数,则再判断学院编号是否为01,02,03,20,其中之一,若不为,非法输入,若为,再判断从右到左依次两位数属于什么特定东西,输出特定东西。第七题我的思路是定义三个浮点型可输入的变量,如果此变量不在题目所给的范围内,输入非法,如果在所给的范围内,如果三条边不能构成三角形,输出一段,如果可以先判断是否为等边三角形,若是,输出一段,不是的话再判断是否为等腰三角形,是判断一下是否为直角三角形,是输出一段,不是输出一段,若不是等腰三角形,再判断是否为直角三角形,是和不是分别输出一段,最终输出结果。第八题我的思路是定义两个浮点数型的可输入变量,再定义一个不可输入的变量用上面两个变量关系赋值表示,如果那两个变量分别小于0,小于等于0,则非法输入,否则再用一个循环表示最终的差值是否小于0.01,最终输出结果。第九题我的思路是定义一个字符串变量赋值为空,然后遍历输入的字符串,当为0或1时和不是进行相应地操作。
第二次作业第一题我的思路是先定义一个可输入的字符串变量,定义一个古典变量,用循环访问字符串的每个字符,若在a与z或A与Z之间,则古典变量赋予一个类型,否则赋予相反类型,若不在,则非法输入,然后用古典变量作为if判断条件,进行大写字母转换数字或小写字母转换数字的情况执行相应的操作。第二题我的思路是定义一个可输入的字符串变量,用字符串的长度和正则表达式判断输入的合法性,若少于11位或者输入数据全1没有起始位,则输出null data,然后再用循环访问该字符串的每一个字符,若为0并且自start变量从0和1,该字符串的第start+10位则按要求输出,否则如果为1,在进行如下操作,再接着以判断里面的古典变量作为if执行接下来所对应的情况,最终得到输出结果。
PowerDesigner相应类图:
第三题我的思路是定义一个输入一整行的可输入的字符串,判断位数是否为8的倍数,不是非法输入,是的话定义一个n个的一维数组,并调用string函数截取当中的字符串进行讨论得到最终结果。
第三次作业的第一题我的思路是定义一个输入一整行的变量,调用 String函数将空格前的字符串提取以及空格后的字符串提取,并讨论是否有逗号以及逗号的个数,若逗号个数并不等于1并且空格数等于逗号数-1并且点输入都符合要求则为超过点的个数,若为1个逗号则再讨论两边是否为double类型的数,用正则表达式判断,但是符号+-得单独判断,若满足两个点,再计算他们的距离,此时得创建一个类联系他们,若不满足,则非法输入,除此之外都非法输入。
PowerDesigner相应类图:
第二题我的思路是定义一个输入一整行的变量,调用 String函数将空格前的字符串提取以及空格后的字符串提取,并讨论是否有逗号以及逗号的个数,若逗号个数并不等于题目要求输入点的个数并且空格数等于逗号数-1并且点输入都符合要求则为超过点的个数,若为输入点的个数个逗号则再讨论两边是否为double类型的数,用正则表达式判断,但是符号+-得单独判断,若满足,输出true,若不满足,则输出false,定义一个函数判断是否为一个点,再定义一个函数判断格式输入符不符合要求以及超出点的个数,再定义一个函数判断两条线段构成直线的位置关系,定义一个函数判断三个点是否在一条直线上,对于选项,用Switch和case进行筛选,现版本Java支持筛选字符串,然后将各个选项用split分离即可。
PowerDesigner相应类图:
第三题我的思路是定义一个输入一整行的变量,调用 String函数将空格前的字符串提取以及空格后的字符串提取,并讨论是否有逗号以及逗号的个数,若逗号个数并不等于题目要求输入点的个数并且空格数等于逗号数-1并且点输入都符合要求则为超过点的个数,若为输入点的个数个逗号则再讨论两边是否为double类型的数,用正则表达式判断,但是符号+-得单独判断,若满足,输出true,若不满足,则输出false,定义一个函数判断是否为一个点,再定义一个函数判断格式输入符不符合要求以及超出点的个数,再定义一个函数判断两条线段构成直线的位置关系,定义一个函数判断三个点是否在一条直线上,对于选项,用Switch和case进行筛选,现版本Java支持筛选字符串,然后将各个选项用split分离即可,然后分别定义函数做执行各选项的操作。
PowerDesigner相应类图:
第四次作业第一题我的思路是定义一个输入变量,遍历其中的各个字符,若字符介于‘0’或‘9’之间,比较的是ASCII码,则将字符变成数值,累加其和。然后输出和。第二题我的思路是定义一个输入一整行的变量,调用 String函数将空格前的字符串提取以及空格后的字符串提取,并讨论是否有逗号以及逗号的个数,若逗号个数并不等于题目要求输入点的个数并且空格数等于逗号数-1并且点输入都符合要求则为超过点的个数,若为输入点的个数个逗号则再讨论两边是否为double类型的数,用正则表达式判断,但是符号+-得单独判断,若满足,输出true,若不满足,则输出false,定义一个函数判断是否为一个点,再定义一个函数判断格式输入符不符合要求以及超出点的个数,再定义一个函数判断两条线段构成直线的位置关系,定义一个函数判断三个点是否在一条直线上,对于选项,用Switch和case进行筛选,现版本Java支持筛选字符串,然后将各个选项用split分离即可,然后分别定义函数做执行各选项的操作,定义函数是否为四边形,再定义一个一条直线与四边形的交点个数的函数。没写完所以没有PowerDesigner相应类图
第三题我的思路是定义两个类,一个是主类,一个是BankBusiness类。在BankBusiness类中定义私有变量name,password和balance,然后在类里面添加获得私有属性以及返回私有属性的函数,以及题目要求的各个函数即可,主函数则是定义一个变量为BankBusiness类的一个对象,再定义多个输入输入变量,交替于执行操作之中即可。
PowerDesigner相应类图:
第五次作业第一题我的思路是定义一个输入一整行的变量,调用 String函数将空格前的字符串提取以及空格后的字符串提取,并讨论是否有逗号以及逗号的个数,若逗号个数并不等于题目要求输入点的个数并且空格数等于逗号数-1并且点输入都符合要求则为超过点的个数,若为输入点的个数个逗号则再讨论两边是否为double类型的数,用正则表达式判断,但是符号+-得单独判断,若满足,输出true,若不满足,则输出false,定义一个函数判断是否为一个点,再定义一个函数判断格式输入符不符合要求以及超出点的个数,再定义一个函数判断两条线段构成直线的位置关系,定义一个函数判断三个点是否在一条直线上,对于选项,用Switch和case进行筛选,现版本Java支持筛选字符串,然后将各个选项用split分离即可,然后分别定义函数做执行各选项的操作,定义函数在输入五个点的情况下是否为五边形,四边形,三角形,再定义一个一条直线与多边形的交点个数的函数,再定义一个算多边形面积的函数,定义一个是否为凹凸多边形的函数。
PowerDesigner相应类图:
第二题我的思路是定义一个输入一整行的变量,调用 String函数将空格前的字符串提取以及空格后的字符串提取,并讨论是否有逗号以及逗号的个数,若逗号个数并不等于题目要求输入点的个数并且空格数等于逗号数-1并且点输入都符合要求则为超过点的个数,若为输入点的个数个逗号则再讨论两边是否为double类型的数,用正则表达式判断,但是符号+-得单独判断,若满足,输出true,若不满足,则输出false,定义一个函数判断是否为一个点,再定义一个函数判断格式输入符不符合要求以及超出点的个数,再定义一个函数判断两条线段构成直线的位置关系,定义一个函数判断三个点是否在一条直线上,对于选项,用Switch和case进行筛选,现版本Java支持筛选字符串,然后将各个选项用split分离即可,然后分别定义函数做执行各选项的操作,定义函数在输入五个点的情况下是否为五边形,四边形,三角形,再定义一个一条直线与多边形的交点个数的函数,再定义一个算多边形面积的函数,定义一个是否为凹凸多边形的函数,其余我不会。所以无PowerDesigner相应类图。
期中考试第一题我的思路是定义三个类,一个主类,其余分别是Line类和Point类,在Point类中定义私有属性横纵坐标,再定义一个获得该值以及返回该值的函数,还有一个display函数。在Line类中定义私有属性两个点和颜色,再定义一个获得该点以及返回该点的函数,再定义一个获得该颜色以及返回该颜色的函数,还有一个display函数,主函数定义一个Line类的对象和两个Point类的对象,再进行相应操作。
PowerDesigner相应类图:
第二题我的思路是定义五个类,一个主类,其余分别是Line类和Point类和Plane类和父类Element类,在Point类中定义私有属性横纵坐标,再定义一个获得该值以及返回该值的函数,还有一个display函数。在Line类中定义私有属性两个点和颜色,再定义一个获得该点以及返回该点的函数,再定义一个获得该颜色以及返回该颜色的函数,在Plane类中定义私有属性颜色,再定义一个获得该颜色以及返回该颜色的函数还有一个display函数,在Element中定义一个dislplay函数里面不用写东西,主函数定义一个Line类的对象和两个Point类的对象和一个Plane类的对象和一个Element类的对象,再进行相应操作。
PowerDesigner相应类图:
第三题不会写,但是PowerDesigner相应类图:
踩坑心得和改进建议:第一次作业第一题边界值没有取,由于在eclipse中无影响,而pta不能得全分最后一次提交修改过来了,所以无法截图,如下图划横线即为边界值,每次情况都要加=
第一次作业第二题一开始写代码的时候全用了double结果部分正确,最后将double改为float后就写对了。如下图,类型不同,输出结果有差异
所以要求严格认识double和float带来的差异
第一次作业第三题无问题
第一次作业第四题也是同第二题一样为浮点数类型的问题,将double改为float后就可行了
第一次作业第五题没有问题
第一次作业第六题无问题
第一次作业第七题中判断三角形是否为直角三角形时若两边的平方和等于第三边的平方和是错误的,应该是两边的平方和减去第三边的平方和小于0。01才算,因为三边均为浮点数,有精确度。在eclipse无法展现他们的区别和部分正确以及全部正确,所以无法截图。
第一次作业第八题也是double类型和浮点数类型的问题,将变量全用浮点数表示即可,与第二题一样的情况。
第一次作业第九题无问题
第二次作业第一题无问题
第二次作业第二题会漏判断条件
第二次作业第三题无问题
第三次作业第一题和第二题和第三题由于未在Pta上交完所以无法截图分析问题,未对点的个数超过2个的情况进行判断。改进建议以代码形式发出
第一题源码
import java.util.Scanner;
public class Main {
public static boolean isNumeric(String str){
if(str.matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
{
if(str.charAt(0) =='0')
{
if(str.length() >= 2)
if(str.charAt(str.length() - 1) != '.')
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return false;
else
return true;
else
return false;
else
return true;
}
else
if(str.charAt(str.length() - 1) != '.')
return true;
else
return false;
}
else if(str.charAt(0) == '+'||str.charAt(0) == '-')
{
if(str.length() == 1)
return false;
else if(str.length() >= 3)
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
if(str.charAt(1) =='0')
if(str.charAt(str.length() - 1) != '.')
if(str.substring(2,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return false;
else
return true;
else
return false;
else
if(str.charAt(str.length() - 1) != '.')
return true;
else
return false;
else
return false;
else
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return true;
else
return false;
}
else
{
return false;
}
}
public static boolean point(String str1,String str2) {
if(isNumeric(str1) == true&&isNumeric(str2) == true)
return true;
else
return false;
}
public static boolean dhgs(String str) {
int cnt = 0;
for(int i = 0;i < str.length();i++) {
if(str.charAt(i) == ',') {
cnt++;
}
}
if(cnt == 1)
return true;
else
return false;
}
public static double distance(double x1,double y1,double x2,double y2){
double distance;
distance = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
return distance;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int cnt = 0;
double a,b,c,d;
String str = in.nextLine();
String[] s = str.split(" ");
if(s.length - 1 > 1) {
for(int i = 0;i < s.length;i++) {
if(dhgs(s[i]) == true&&s[i].split(",").length == 2&&point(s[i].split(",")[0],s[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s.length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s.length == 1)//考虑未输入也算点的个数错误,而输入未含空格的字符串则非法输入
if(str == "")//或者条件可以写为else if(str == null)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
else if(s.length == 0)//考虑输入全是空格为非法输入
System.out.print("Wrong Format");
else {
for(int i = 0;i < s.length;i++) {
if(dhgs(s[i]) == true&&s[i].split(",").length == 2&&point(s[i].split(",")[0],s[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s.length) {
if(str.charAt(str.length() - 1) != ' ') {
a = Double.parseDouble(s[0].split(",")[0]);
b = Double.parseDouble(s[0].split(",")[1]);
c = Double.parseDouble(s[1].split(",")[0]);
d = Double.parseDouble(s[1].split(",")[1]);
System.out.print(distance(a,b,c,d));
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
in.close();
}
}
第二题源代码
import java.util.Scanner;
public class Main {
public static boolean isNumeric(String str){
if(str.matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
{
if(str.charAt(0) =='0')
{
if(str.length() >= 2)
if(str.charAt(str.length() - 1) != '.')
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return false;
else
return true;
else
return false;
else
return true;
}
else
if(str.charAt(str.length() - 1) != '.')
return true;
else
return false;
}
else if(str.charAt(0) == '+'||str.charAt(0) == '-')
{
if(str.length() == 1)
return false;
else if(str.length() >= 3)
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
if(str.charAt(1) =='0')
if(str.charAt(str.length() - 1) != '.')
if(str.substring(2,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return false;
else
return true;
else
return false;
else
if(str.charAt(str.length() - 1) != '.')
return true;
else
return false;
else
return false;
else
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return true;
else
return false;
}
else
{
return false;
}
}
public static boolean point(String str1,String str2) {
if(isNumeric(str1) == true&&isNumeric(str2) == true)
return true;
else
return false;
}
public static boolean dhgs(String str) {
int cnt = 0;
for(int i = 0;i < str.length();i++) {
if(str.charAt(i) == ',') {
cnt++;
}
}
if(cnt == 1)
return true;
else
return false;
}
public static double xielv(double x1,double y1,double x2,double y2) {
double xielv = (y2 - y1)/(x2 - x1);
return xielv;
}
public static void One(String str) {
int cnt = 0;
double a,b,c,d;
String[] s = str.split("1:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 1) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) != ' ') {
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
if(a == c)
if(b == d)
System.out.print("points coincide");
else
System.out.print("Slope does not exist");
else
System.out.print(xielv(a,b,c,d));
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void Two(String str){
int cnt = 0;
double a,b,c,d,e,f;
double czjl;
String[] s = str.split("2:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 2||s[1].split(" ").length - 1 == 1) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
if(c == e)
if(d == f)
System.out.print("points coincide");
else
System.out.print(Math.abs(a -c));
else{
czjl = Math.abs((xielv(c,d,e,f)*a - b + d - xielv(c,d,e,f)*c)/Math.sqrt(Math.pow(xielv(c,d,e,f), 2) + 1));
System.out.print(czjl);
}
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void Three(String str){
int cnt = 0;
double a,b,c,d,e,f;
String[] s = str.split("3:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 2||s[1].split(" ").length - 1 == 1) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
if((a == c&&b == d)||(a == e&&b == f)||(c == e&&d == f))
System.out.print("points coincide");
else
if((c - a)*(f - d) == (d - b)*(e - c))
System.out.print("true");
else
System.out.print("false");
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void Four(String str){
int cnt = 0;
double a,b,c,d,e,f,g,h;
String[] s = str.split("4:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 3||s[1].split(" ").length - 1 == 1||s[1].split(" ").length - 1 == 2) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
g = Double.parseDouble(s[1].split(" ")[3].split(",")[0]);
h = Double.parseDouble(s[1].split(" ")[3].split(",")[1]);
if((a == c&&b == d)||(e == g&&f == h))
System.out.print("points coincide");
else
if((c - a)*(f - d) == (d - b)*(e - c))
System.out.print("false");
else
if((c - a)*(h - d) == (d - b)*(g - c))
System.out.print("false");
else
if((c - a)*(h - f) == (d - b)*(g - e))
System.out.print("true");
else
System.out.print("false");
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void Five(String str){
int cnt = 0;
double a,b,c,d,e,f,g,h;
double jiaodianx,jiaodiany;
String[] s = str.split("5:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 3||s[1].split(" ").length - 1 == 1||s[1].split(" ").length - 1 == 2) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
g = Double.parseDouble(s[1].split(" ")[3].split(",")[0]);
h = Double.parseDouble(s[1].split(" ")[3].split(",")[1]);
if((a == c&&b == d)||(e == g&&f == h))
System.out.print("points coincide");
else
if((c - a)*(f - d) == (d - b)*(e - c))
if((c - a)*(h - d) == (d - b)*(g - c))
System.out.print("is coincident lines,have infinite intersection points");
else {
System.out.print(e + "," + f);
if(f >= Math.max(b,d)||f <= Math.min(b, d))
System.out.print(" false");
else
System.out.print(" true");
}
else
if((c - a)*(h - d) == (d - b)*(g - c)) {
System.out.print(g + "," + h);
if(h >= Math.max(b,d)||h <= Math.min(b, d))
System.out.print(" false");
else
System.out.print(" true");
}
else
if((c - a)*(h - f) == (d - b)*(g - e))
System.out.print("is parallel lines,have no intersection point");
else
if(a == c){
jiaodiany = xielv(e,f,g,h)*a + f - xielv(e,f,g,h)*e;
System.out.print(a + "," + jiaodiany);
if((jiaodiany >= Math.max(b, d)&&jiaodiany >= Math.max(f, h))||(jiaodiany <= Math.min(b, d)&&jiaodiany <= Math.min(f, h)))
System.out.print(" false");
else
System.out.print(" true");
}
else{
if(e == g){
jiaodiany = xielv(a,b,c,d)*e + b - xielv(a,b,c,d)*a;
System.out.print(e + "," + jiaodiany);
if((jiaodiany >= Math.max(b, d)&&jiaodiany >= Math.max(f, h))||(jiaodiany <= Math.min(b, d)&&jiaodiany <= Math.min(f, h)))
System.out.print(" false");
else
System.out.print(" true");
}
else{
jiaodianx = (f - xielv(e,f,g,h)*e - b + xielv(a,b,c,d)*a)/(xielv(a,b,c,d) - xielv(e,f,g,h));
jiaodiany = xielv(a,b,c,d)*jiaodianx + b - xielv(a,b,c,d)*a;
System.out.print(jiaodianx + "," + jiaodiany);
if((jiaodiany >= Math.max(b, d)&&jiaodiany >= Math.max(f, h))||(jiaodiany <= Math.min(b, d)&&jiaodiany <= Math.min(f, h)))
System.out.print(" false");
else
System.out.print(" true");
}
}
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
String str = in.nextLine();
if(str.length() >= 2) {
switch(str.substring(0, 2)) {
case "1:":One(str);
break;
case "2:":Two(str);
break;
case "3:":Three(str);
break;
case "4:":Four(str);
break;
case "5:":Five(str);
break;
default:System.out.print("Wrong Format");
}
}
else
System.out.print("Wrong Format");
in.close();
}
}
第三题源码
import java.util.Scanner;
import java.math.BigDecimal;
public class Main {
public static boolean isNumeric(String str){
if(str.matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
{
if(str.charAt(0) =='0')
{
if(str.length() >= 2)
if(str.charAt(str.length() - 1) != '.')
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return false;
else
return true;
else
return false;
else
return true;
}
else
if(str.charAt(str.length() - 1) != '.')
return true;
else
return false;
}
else if(str.charAt(0) == '+'||str.charAt(0) == '-')
{
if(str.length() == 1)
return false;
else if(str.length() >= 3)
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
if(str.charAt(1) =='0')
if(str.charAt(str.length() - 1) != '.')
if(str.substring(2,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return false;
else
return true;
else
return false;
else
if(str.charAt(str.length() - 1) != '.')
return true;
else
return false;
else
return false;
else
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return true;
else
return false;
}
else
{
return false;
}
}
public static boolean point(String str1,String str2) {
if(isNumeric(str1) == true&&isNumeric(str2) == true)
return true;
else
return false;
}
public static double jingque(double num) {
if((num+"").length()-(num+"").indexOf(".")-1 > 6) {
BigDecimal bg = new BigDecimal(num);
@SuppressWarnings("deprecation")
double f1 = bg.setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
return f1;
}
else
return num;
}
public static boolean dhgs(String str) {
int cnt = 0;
for(int i = 0;i < str.length();i++) {
if(str.charAt(i) == ',') {
cnt++;
}
}
if(cnt == 1)
return true;
else
return false;
}
public static double xielv(double x1,double y1,double x2,double y2) {
double xielv = (y2 - y1)/(x2 - x1);
return xielv;
}
public static double distance(double x1,double y1,double x2,double y2){
double distance;
distance = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
return distance;
}
public static void One(String str){
int cnt = 0;
double a,b,c,d,e,f;
String[] s = str.split("1:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 2||s[1].split(" ").length - 1 == 1) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
if(distance(a,b,c,d) + distance(c,d,e,f) > distance(a,b,e,f)&&distance(a,b,c,d) + distance(a,b,e,f) > distance(c,d,e,f)&&distance(c,d,e,f) + distance(a,b,e,f) > distance(a,b,c,d))
if(distance(a,b,c,d) == distance(c,d,e,f)||distance(a,b,c,d) == distance(a,b,e,f)||distance(c,d,e,f) == distance(a,b,e,f)) {
System.out.print("true");
if(distance(a,b,c,d) == distance(c,d,e,f)&&distance(a,b,c,d) == distance(a,b,e,f))
System.out.print(" true");
else
System.out.print(" false");
}
else
System.out.print("false" + " " + "false");
else{
System.out.print("data error");
}
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void Two(String str){
int cnt = 0;
double a,b,c,d,e,f;
double zc,mj,zxhzb,zxzzb;
String[] s = str.split("2:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 2||s[1].split(" ").length - 1 == 1) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
if(distance(a,b,c,d) + distance(c,d,e,f) > distance(a,b,e,f)&&distance(a,b,c,d) + distance(a,b,e,f) > distance(c,d,e,f)&&distance(c,d,e,f) + distance(a,b,e,f) > distance(a,b,c,d)) {
zc = distance(a,b,c,d) + distance(c,d,e,f) + distance(a,b,e,f);
mj = Math.sqrt((zc/2.0)*((zc/2.0)-distance(a,b,c,d))*((zc/2.0)-distance(c,d,e,f))*((zc/2.0)-distance(a,b,e,f)));
zxhzb = (a + c + e)/3.0;
zxzzb = (b + d + f)/3.0;
System.out.print(jingque(zc) + " " + jingque(mj) + " " + jingque(zxhzb) + "," + jingque(zxzzb));
}
else{
System.out.print("data error");
}
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
}
public static void Three(String str){
int cnt = 0;
double a,b,c,d,e,f;
String[] s = str.split("3:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 2||s[1].split(" ").length - 1 == 1) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
if(distance(a,b,c,d) + distance(c,d,e,f) > distance(a,b,e,f)&&distance(a,b,c,d) + distance(a,b,e,f) > distance(c,d,e,f)&&distance(c,d,e,f) + distance(a,b,e,f) > distance(a,b,c,d)) {
if(distance(a,b,c,d)*distance(a,b,c,d) + distance(c,d,e,f)*distance(c,d,e,f) == distance(a,b,e,f)*distance(a,b,e,f)||distance(a,b,c,d)*distance(a,b,c,d) + distance(a,b,e,f)*distance(a,b,e,f) == distance(c,d,e,f)*distance(c,d,e,f)||distance(a,b,e,f)*distance(a,b,e,f) + distance(c,d,e,f)*distance(c,d,e,f) == distance(a,b,c,d)*distance(a,b,c,d))
System.out.print("false" + " " + "true" + " "+ "false");
else if(distance(a,b,c,d)*distance(a,b,c,d) + distance(c,d,e,f)*distance(c,d,e,f) > distance(a,b,e,f)*distance(a,b,e,f)||distance(a,b,c,d)*distance(a,b,c,d) + distance(a,b,e,f)*distance(a,b,e,f) > distance(c,d,e,f)*distance(c,d,e,f)||distance(a,b,e,f)*distance(a,b,e,f) + distance(c,d,e,f)*distance(c,d,e,f) > distance(a,b,c,d)*distance(a,b,c,d))
System.out.print("true" + " " + "false" + " "+ "false");
else
System.out.print("false" + " " + "false" + " "+ "true");
}
else{
System.out.print("data error");
}
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void Four(String str){
int cnt = 0;
double a,b,c,d,e,f,g,h,j,k;
String[] s = str.split("4:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 4||s[1].split(" ").length - 1 == 1||s[1].split(" ").length - 1 == 2||s[1].split(" ").length - 1 == 3) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
g = Double.parseDouble(s[1].split(" ")[3].split(",")[0]);
h = Double.parseDouble(s[1].split(" ")[3].split(",")[1]);
j = Double.parseDouble(s[1].split(" ")[4].split(",")[0]);
k = Double.parseDouble(s[1].split(" ")[4].split(",")[1]);
if(a == c&&b == d)
if(distance(e,f,g,h) + distance(g,h,j,k) > distance(e,f,j,k)&&distance(e,f,g,h) + distance(e,f,j,k) > distance(g,h,j,k)&&distance(g,h,j,k) + distance(e,f,j,k) > distance(e,f,g,h))
System.out.print("points coincide");
else
System.out.print("points coincide and data error");
else
if(distance(e,f,g,h) + distance(g,h,j,k) > distance(e,f,j,k)&&distance(e,f,g,h) + distance(e,f,j,k) > distance(g,h,j,k)&&distance(g,h,j,k) + distance(e,f,j,k) > distance(e,f,g,h))
System.out.print("data error");
else
System.out.print("data error");
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void Five(String str){
int cnt = 0;
double a,b,c,d,e,f,g,h;
double jiaodianx,jiaodiany;
String[] s = str.split("5:");
if(s.length == 2) {
if(s[1].split(" ").length - 1 > 3||s[1].split(" ").length - 1 == 1||s[1].split(" ").length - 1 == 2) {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length) {
if(str.charAt(str.length() - 1) == ' ')//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数错误要求,实则输入非法的情况
System.out.print("Wrong Format");
else
System.out.print("wrong number of points");
}
}
else if(s[1].split(" ").length == 1||s[1].split(" ").length == 0)
System.out.print("Wrong Format");
else {
for(int i = 0;i < s[1].split(" ").length;i++) {
if(dhgs(s[1].split(" ")[i]) == true&&s[1].split(" ")[i].split(",").length == 2&&point(s[1].split(" ")[i].split(",")[0],s[1].split(" ")[i].split(",")[1]) == true)
cnt++;
else {
System.out.print("Wrong Format");
break;
}
}
if(cnt == s[1].split(" ").length){
if(str.charAt(str.length() - 1) != ' '){
a = Double.parseDouble(s[1].split(" ")[0].split(",")[0]);
b = Double.parseDouble(s[1].split(" ")[0].split(",")[1]);
c = Double.parseDouble(s[1].split(" ")[1].split(",")[0]);
d = Double.parseDouble(s[1].split(" ")[1].split(",")[1]);
e = Double.parseDouble(s[1].split(" ")[2].split(",")[0]);
f = Double.parseDouble(s[1].split(" ")[2].split(",")[1]);
g = Double.parseDouble(s[1].split(" ")[3].split(",")[0]);
h = Double.parseDouble(s[1].split(" ")[3].split(",")[1]);
if((a == c&&b == d)||(e == g&&f == h))
System.out.print("points coincide");
else
if((c - a)*(f - d) == (d - b)*(e - c))
if((c - a)*(h - d) == (d - b)*(g - c))
System.out.print("is coincident lines,have infinite intersection points");
else
System.out.print(e + "," + f + " false");
else
if((c - a)*(h - d) == (d - b)*(g - c))
System.out.print(g + "," + h + " false");
else
if((c - a)*(h - f) == (d - b)*(g - e))
System.out.print("is parallel lines,have no intersection point");
else
if(a == c){
jiaodiany = xielv(e,f,g,h)*a + f - xielv(e,f,g,h)*e;
System.out.print(a + "," + jiaodiany);
if(jiaodiany >= Math.max(b, d)||jiaodiany <= Math.min(b, d))
System.out.print(" false");
else
System.out.print(" true");
}
else{
if(e == g){
jiaodiany = xielv(a,b,c,d)*e + b - xielv(a,b,c,d)*a;
System.out.print(e + "," + jiaodiany);
if(jiaodiany >= Math.max(f, h)||jiaodiany <= Math.min(f, h))
System.out.print(" false");
else
System.out.print(" true");
}
else{
jiaodianx = (f - xielv(e,f,g,h)*e - b + xielv(a,b,c,d)*a)/(xielv(a,b,c,d) - xielv(e,f,g,h));
jiaodiany = xielv(a,b,c,d)*jiaodianx + b - xielv(a,b,c,d)*a;
System.out.print(jiaodianx + "," + jiaodiany);
if(jiaodiany >= Math.max(b, d)||jiaodiany >= Math.max(f, h)||jiaodiany <= Math.min(b, d)||jiaodiany <= Math.min(f, h))
System.out.print(" false");
else
System.out.print(" true");
}
}
}
else//考虑因输入时在最后一个点的坐标后面加上空格符号导致直观上符合点的个数与格式要求,实则输入非法的情况
System.out.print("Wrong Format");
}
}
}
else if(s.length == 0)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
String str = in.nextLine();
if(str.length() >= 2) {
switch(str.substring(0, 2)) {
case "1:":One(str);
break;
case "2:":Two(str);
break;
case "3:":Three(str);
break;
case "4:":Four(str);
break;
case "5:":Five(str);
break;
default:System.out.print("Wrong Format");
}
}
else
System.out.print("Wrong Format");
in.close();
}
}
第四次作业第一题和第三题无问题
第二题除了格式非法正确,其余操作错误,由于在PTA未交,所以无法截图
改进建议(以源码形式呈现)
第二题源码
import java.util.Scanner;
public class Main {
public static boolean ch(double a1,double b1,double c1,double d1) {
if(a1 == c1&&b1 ==d1)
return true;
else
return false;
}
public static boolean isNumeric(String str){
if(str.matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
{
if(str.charAt(0) =='0')
{
if(str.length() >= 2)
if(str.charAt(str.length() - 1) != '.')
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return false;
else
return true;
else
return false;
else
return true;
}
else
if(str.charAt(str.length() - 1) != '.')
return true;
else
return false;
}
else if(str.charAt(0) == '+'||str.charAt(0) == '-')
{
if(str.length() == 1)
return false;
else if(str.length() >= 3)
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
if(str.charAt(1) =='0')
if(str.charAt(str.length() - 1) != '.')
if(str.substring(2,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return false;
else
return true;
else
return false;
else
if(str.charAt(str.length() - 1) != '.')
return true;
else
return false;
else
return false;
else
if(str.substring(1,str.length()).matches("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}"))
return true;
else
return false;
}
else
{
return false;
}
}
public static void Onefuhe(String str) {
String[] s = str.split(" ");
// String s5 = s[0];
// String s2 = s[1];
// String s3 = s[2];
// String s4 = s[3];
// String s1 = s5.substring(2,s5.length());
String s11 = s[0].substring(2,s[0].length()).split(",")[0];
String s12 = s[0].substring(2,s[0].length()).split(",")[1];
String s21 = s[1].split(",")[0];
String s22 = s[1].split(",")[1];
String s31 = s[2].split(",")[0];
String s32 = s[2].split(",")[1];
String s41 = s[3].split(",")[0];
String s42 = s[3].split(",")[1];
double a = Double.parseDouble(s11);
double b = Double.parseDouble(s12);
double c = Double.parseDouble(s21);
double d = Double.parseDouble(s22);
double e = Double.parseDouble(s31);
double f = Double.parseDouble(s32);
double g = Double.parseDouble(s41);
double h = Double.parseDouble(s42);
if(isNumeric(s11)&&isNumeric(s12)&&isNumeric(s21)&&isNumeric(s22)&&isNumeric(s31)&&isNumeric(s32)&&isNumeric(s41)&&isNumeric(s42))
{
if(ch(a,b,c,d)||ch(a,b,e,f)||ch(a,b,g,h)||ch(c,d,e,f)||ch(c,d,g,h)||ch(e,f,g,h))
System.out.print("points coincide");
else
if((c-a)*(h-f) == (d-b)*(g-e)&&((c-a)*(c-a) + (d-b)*(d-b)) == ((g-e)*(g-e) + (h-f)*(h-f)))
System.out.print("true");
else
System.out.print("false");
}
else
System.out.print("Wrong Format");
}
public static int blankof(String str)
{
int blank = 0;
for(int i = 0;i < str.length();i++)
{
if(str.charAt(i) == ' ')
blank++;
}
return blank;
}
public static int douhaoof(String str)
{
int douhao = 0;
for(int i = 0;i < str.length();i++)
{
if(str.charAt(i) == ' ')
douhao++;
}
return douhao;
}
public static void One(String str)
{
String[] s = str.split(" ");
String s1 = s[0];
if(blankof(str) == 3&&douhaoof(str) == 4)
if(str.charAt(0) == '1'&&str.charAt(1) == ':')
Onefuhe(str);
else
System.out.print("Wrong Format");
else if(douhaoof(str) == blankof(str) + 1)
System.out.print("wrong number of points");
else
System.out.print("Wrong Format");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
String str = in.nextLine();
One(str);
}
}
class Point {
}
代码未写完
第五次作业第一题
计算之后的都不会写
改进建议无,不会写
第二题整道题0分,不会写
期中考试第一二题无问题,第三题不会写
总结:1.Java的运行(基础必备) 这条可能出看很简单,java程序的运行谁不会呢?不过很多时候, 我们只是单纯通过IDE去执行java程序,底层IDE又是如何执行java程序呢?很多人并不了解。
2.这个知识点是最最基本的java开发者需要掌握的,初学java,第一个肯定是教你如何在命令行中执行java程序,但是很多人一旦把java学完 了,IDE用上了,就把这个都忘了。为什么强调要知道这个呢,知道了java最纯粹的启动方式之后,你才能在启动出问题的时候,去分析当时启动的目录多少,执行命名如何,参数如何,是否有缺失等。 这样有利于你真正开发中去解决那些奇奇怪怪的可能和环境相关的问题。
在这里需要掌握的知识有: javac 编译java文件为 class 文件java 命令的使用, 带package的java类如何在命令行中启动java程序涉及到的各个路径(classpath, java。library。path, java运行的主目录等)
3.数据类型 这条没有什么好多说的,无非就是Java中的基本类型和对象类型的掌握。可以再了解一些JDK如何自动转换方面的知识,包括装箱拆箱等,还要注意避免装箱之后的类型相等的判断 主要知识点: 基本类型: int, long, float, double, boolean ······ 对应的对象类型: Integer 等类型到基本类型的转换, 装箱和拆箱Object类型: equals, hashcodeString 类型的特点
4.对象和实例,对象的创建 ,在这方面,开发者需要了解class和instance的概念以及之间的差别, 这是java面向对象特性的一个基础。
主要知识点有:Class和 Instance 的概念; Instance 创建的过程:1. 无继承:分配内存空间, 初始化变量, 调用构造函数;2.有继承:处理静态动作, 分配内存空间, 变量定义为初始值 , 从基类->子类, 处理定义处的初始化, 执行构造方法; 需要注意的点:静态属性等从基类->子类进行初始化;默认无参构造方法相关的特性。
5.访问控制 这也是java封装特性的一个基础需要掌握的有:public protected default private 对于class, method, field 的修饰作用
6.流程控制 Java 流程控制的基础,虽然有些语法不一定很常用,但是都需要了解,并且在合适的地方使用它们。需要掌握的有: if, switch, loop, for, while 等流程控制的语法
7.面向对象编程的概念 这是一个java的核心概念,对于任何java开发者都需要熟练掌握。Java中很多特性或者说知识点都是和java面向对象编程概念相关的。在我的理解, 一个好的开发者不仅仅需要了解这些特性(知识点)本身,也更需要知道这些对象在java的面向对象编程概念中是如何体现出来的,这样更有利于开发者掌握 java这门开发语言,以及其他面向对象编程的语言。
主要的知识点包括有:面向对象三大特性:封装,继承,多态; 各自的定义概念,有哪些特性体现出 来,各自的使用场景静态多分派,动态单分派的概念重载的概念和使用继承:接口多实现,基类单继承抽象,抽象类,接口多态:方法覆盖的概念和使用接口回调
8.Static 静态属性在java日常开发中也是经常使用,需要了解和 static 关键字相关的用法,还有和其他关键字的配合使用, 如是否可以和 abstract, final 等关键字联合使用。 主要需要掌握的有:静态属性的定义,使用,以及类加载时如何初始化静态方法的定义和使用静态类的定义和使用静态代码块的定义和初始化时机。
9.学会了类与类类与对象之间的关系,知道怎么写点线形类题目。
10.对教师和课上尽量不要很快的讲新东西,需要有一个细嚼慢咽的过程,希望教师多多讲一下作业该怎么写以及一些基础知识的温习,作业方面尽量出一些难易结合的题目,而不是都是难题,实验课上希望老师在实验方面能够指导一下学生往哪个方向思考。