From f5df8c0e7073fd2e7435433f967bef6b9ea42ce6 Mon Sep 17 00:00:00 2001 From: Samler <15181536@qq.com> Date: Wed, 18 Nov 2020 11:56:14 +0800 Subject: [PATCH 1/9] =?UTF-8?q?!11=20Sync=20*=20update=20README.md.=20*=20?= =?UTF-8?q?!10=20Update=20Exp06=20source=20code=20*=20!8=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=A4=A9=E6=A2=AF=E9=A2=98=E9=9B=86=20=E6=9D=A5?= =?UTF-8?q?=E8=87=AA=E8=B4=A1=E7=8C=AE=E8=80=85[@small=5Flin168]=20*=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20PTA/tianti=20*=20!5=207-?= =?UTF-8?q?8=20=E6=9F=A5=E9=AA=8C=E8=BA=AB=E4=BB=BD=E8=AF=81=20(15?= =?UTF-8?q?=E5=88=86)=20*=20!3=20add=20PTA/tianti.=20*=20add=20PTA/tianti.?= =?UTF-8?q?=20*=20!2=20update=20README.md=20*=20update=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 412fac3..e516270 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ### 作业查看入口 - PTA作业:[/PTA](/PTA) -- 实验作业(待整理):[/EXP](/EXP) +- 实验作业(待完善):[/EXP](/EXP) 由于前期未进行作业的整理,因此早前的部分作业代码可能没有放上来,敬请谅解。 -- Gitee From e6ec5871a3bd4ee29782013831ac23c1dca7192c Mon Sep 17 00:00:00 2001 From: Samler <15181536@qq.com> Date: Wed, 18 Nov 2020 13:09:17 +0800 Subject: [PATCH 2/9] update EXP/Exp06/README.md. --- EXP/Exp06/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EXP/Exp06/README.md b/EXP/Exp06/README.md index 6f15081..f89e0ce 100644 --- a/EXP/Exp06/README.md +++ b/EXP/Exp06/README.md @@ -1,11 +1,11 @@ ## 实验6作业代码 ### 题目详情 - A Bank Account Class - - [Account.java](./Exp/Exp06/Problem01/Account.java) - - [ManageAccounts](./Exp/Exp06/Problem01/ManageAccounts.java) + - [Account.java](./Problem01/Account.java) + - [ManageAccounts](./Problem01/ManageAccounts.java) - Representing Names - - [Name.java](./Exp/Exp06/Problem02/Name.java) - - [TestNamesName.java](./Exp/Exp06/Problem02/TestNames.java) + - [Name.java](./Problem02/Name.java) + - [TestNamesName.java](./Problem02/TestNames.java) ### 讨论和建议 如果大家在查看过程中发现错误或不足之处,欢迎大家在[Issues](https://gitee.com/Samler/java-work/issues)中发表自己的见解,也欢迎大家在[Issues](https://gitee.com/Samler/java-work/issues)中进行讨论。 -- Gitee From a7b6c27d1bac1bc22bff502e0e9bc5efb080b513 Mon Sep 17 00:00:00 2001 From: Samler <15181536@qq.com> Date: Wed, 25 Nov 2020 16:17:39 +0800 Subject: [PATCH 3/9] upload ProblemSet05 and ProblemSet06 --- PTA/ProblemSet05/Problem01/Main.java | 22 +++++++ PTA/ProblemSet05/Problem02/Main.java | 27 +++++++++ PTA/ProblemSet05/Problem03/Main.java | 23 +++++++ PTA/ProblemSet06/Problem01/Main.java | 47 ++++++++++++++ PTA/ProblemSet06/Problem02/Main.java | 76 +++++++++++++++++++++++ PTA/ProblemSet06/Problem03/Main.java | 37 +++++++++++ PTA/ProblemSet06/Problem04/Main.java | 24 ++++++++ PTA/ProblemSet06/Problem05/Main.java | 49 +++++++++++++++ PTA/ProblemSet06/Problem06/Main.java | 91 ++++++++++++++++++++++++++++ 9 files changed, 396 insertions(+) create mode 100644 PTA/ProblemSet05/Problem01/Main.java create mode 100644 PTA/ProblemSet05/Problem02/Main.java create mode 100644 PTA/ProblemSet05/Problem03/Main.java create mode 100644 PTA/ProblemSet06/Problem01/Main.java create mode 100644 PTA/ProblemSet06/Problem02/Main.java create mode 100644 PTA/ProblemSet06/Problem03/Main.java create mode 100644 PTA/ProblemSet06/Problem04/Main.java create mode 100644 PTA/ProblemSet06/Problem05/Main.java create mode 100644 PTA/ProblemSet06/Problem06/Main.java diff --git a/PTA/ProblemSet05/Problem01/Main.java b/PTA/ProblemSet05/Problem01/Main.java new file mode 100644 index 0000000..f9cfd5f --- /dev/null +++ b/PTA/ProblemSet05/Problem01/Main.java @@ -0,0 +1,22 @@ +package ProblemSet05.Problem01; + +public class Main { + public static void main(String[] args) { + System.out.println("车牌号码是" + getCode()); + } + + public static String getCode() { + for(int i = 1; i <= 9; i++) { + for(int j = 1; j <= 9; j++) { + int code = i * 1100 + j * 11, + item = (int) Math.sqrt(code); + + if(Math.pow(item, 2) == code && i != j) { + return Integer.toString(code); + } + } + } + + return null; + } +} diff --git a/PTA/ProblemSet05/Problem02/Main.java b/PTA/ProblemSet05/Problem02/Main.java new file mode 100644 index 0000000..c49fdb7 --- /dev/null +++ b/PTA/ProblemSet05/Problem02/Main.java @@ -0,0 +1,27 @@ +package ProblemSet05.Problem02; + +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + String str = scan.nextLine(); + scan.close(); + + System.out.println(isPalindrome(str, str.length(), 0) ? "yes" : "no"); + } + + public static boolean isPalindrome(String str, int length, int offset) { + if (length < 2) return false; + + int middleIndex = length / 2, + fixOffset = (length % 2 == 0) ? 0 : 1; + //fixOffset用于修正偶数情况下偏移量不对称问题 + + if(middleIndex + offset + fixOffset >= length) return true; + if(str.charAt(middleIndex + fixOffset + offset) == str.charAt(middleIndex - offset - 1)) + return isPalindrome(str, length, ++offset); + + return false; + } +} diff --git a/PTA/ProblemSet05/Problem03/Main.java b/PTA/ProblemSet05/Problem03/Main.java new file mode 100644 index 0000000..6567e64 --- /dev/null +++ b/PTA/ProblemSet05/Problem03/Main.java @@ -0,0 +1,23 @@ +package ProblemSet05.Problem03; + +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int len = scan.nextInt(); + int[] hArray = new int[len]; + + for(int i = 0; i < len; i++) + hArray[i] = scan.nextInt(); + scan.close(); + + System.out.println(getMax(hArray, 0, hArray[0])); + } + + public static int getMax(int[] arr, int index, int max) { + if(index > arr.length - 1) return max; + + return getMax(arr, index + 1, arr[index] > max ? arr[index] : max); + } +} diff --git a/PTA/ProblemSet06/Problem01/Main.java b/PTA/ProblemSet06/Problem01/Main.java new file mode 100644 index 0000000..58ab523 --- /dev/null +++ b/PTA/ProblemSet06/Problem01/Main.java @@ -0,0 +1,47 @@ +package ProblemSet06.Problem01; + +import java.util.Arrays; +import java.util.Scanner; + +class PersonSortable implements Comparable{ + private String name; + private int age; + + public PersonSortable(String name, int age) { + this.name = name; + this.age = age; + } + + public String toString() { + return name + "-" + age; + } + + public int compareTo(PersonSortable o) { + int nameCompareResult = this.name.compareTo(o.name); + if(nameCompareResult == 0) + return this.age - o.age; + + return nameCompareResult; + } +} + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int len = Integer.parseInt(scan.nextLine()); + PersonSortable[] pList = new PersonSortable[len]; + + for(int i = 0; i < len; i++) { + String[] pData = scan.nextLine().split(" "); + pList[i] = new PersonSortable(pData[0], Integer.parseInt(pData[1])); + } + scan.close(); + + Arrays.sort(pList); + for(PersonSortable p : pList) + System.out.println(p); + + System.out.println(Arrays.toString(PersonSortable.class.getInterfaces())); + } +} + diff --git a/PTA/ProblemSet06/Problem02/Main.java b/PTA/ProblemSet06/Problem02/Main.java new file mode 100644 index 0000000..b3fafe6 --- /dev/null +++ b/PTA/ProblemSet06/Problem02/Main.java @@ -0,0 +1,76 @@ +package ProblemSet06.Problem02; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.Scanner; + +class PersonSortable2 { + private String name; + private int age; + + public PersonSortable2(String name, int age) { + this.name = name; + this.age = age; + } + + public String toString() { + return name + "-" + age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } +} + +class NameComparator implements Comparator { + + public int compare(PersonSortable2 o1, PersonSortable2 o2) { + return o1.getName().compareTo(o2.getName()); + } + +} + +class AgeComparator implements Comparator { + + public int compare(PersonSortable2 o1, PersonSortable2 o2) { + return o1.getAge() - o2.getAge(); + } + +} + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int len = Integer.parseInt(scan.nextLine()); + PersonSortable2[] pList = new PersonSortable2[len]; + + for(int i = 0; i < len; i++) { + String[] pData = scan.nextLine().split(" "); + pList[i] = new PersonSortable2(pData[0], Integer.parseInt(pData[1])); + } + scan.close(); + + Arrays.sort(pList, new NameComparator()); + System.out.println("NameComparator:sort"); + for(PersonSortable2 p : pList) System.out.println(p); + + Arrays.sort(pList, new AgeComparator()); + System.out.println("AgeComparator:sort"); + for(PersonSortable2 p : pList) System.out.println(p); + + System.out.println(Arrays.toString(NameComparator.class.getInterfaces())); + System.out.println(Arrays.toString(AgeComparator.class.getInterfaces())); + } +} diff --git a/PTA/ProblemSet06/Problem03/Main.java b/PTA/ProblemSet06/Problem03/Main.java new file mode 100644 index 0000000..113b9fe --- /dev/null +++ b/PTA/ProblemSet06/Problem03/Main.java @@ -0,0 +1,37 @@ +package ProblemSet06.Problem03; + +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + int[] arr = new int[5]; + Scanner scan = new Scanner(System.in); + boolean continueListen = true; + + while(continueListen) { + String[] cmd = scan.nextLine().split(" "); + try { + switch(cmd[0]) { + case "arr": + arr[Integer.parseInt(cmd[1])] = 0; + break; + case "null": + throw new NullPointerException(); + case "cast": + @SuppressWarnings("unused") + Integer tmp = (Integer)((Object) new String("")); + break; + case "num": + Integer.parseInt(cmd[1]); + break; + default: + continueListen = false; + } + } catch (Exception e) { + System.out.println(e); + } + } + + scan.close(); + } +} diff --git a/PTA/ProblemSet06/Problem04/Main.java b/PTA/ProblemSet06/Problem04/Main.java new file mode 100644 index 0000000..46ca5c8 --- /dev/null +++ b/PTA/ProblemSet06/Problem04/Main.java @@ -0,0 +1,24 @@ +package ProblemSet06.Problem04; + +import java.util.Scanner; +import java.util.Arrays; + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int n = scan.nextInt(); + int[] numArr = new int[n]; + + for(int i = 0; i < n; i++) { + try { + numArr[i] = Integer.parseInt(scan.next()); + } catch (Exception e) { + i--; + System.out.println(e); + } + } + scan.close(); + + System.out.println(Arrays.toString(numArr)); + } +} diff --git a/PTA/ProblemSet06/Problem05/Main.java b/PTA/ProblemSet06/Problem05/Main.java new file mode 100644 index 0000000..c3a3943 --- /dev/null +++ b/PTA/ProblemSet06/Problem05/Main.java @@ -0,0 +1,49 @@ +package ProblemSet06.Problem05; + +import java.util.Scanner; + +class ArrayUtils { + public static double findMax(double[] arr, int begin, int end) throws IllegalArgumentException { + if(begin < 0) throw new IllegalArgumentException("begin:" + begin + " < 0"); + else if(begin >= end) throw new IllegalArgumentException("begin:" + begin + " >= end:" + end); + else if(end > arr.length) throw new IllegalArgumentException("end:" + end + " > arr.length"); + + double max = arr[begin]; + for(int i = begin; i < end; i++) { + if(arr[i] > max) max = arr[i]; + } + + return max; + } +} + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + int n = scan.nextInt(); + double[] numArr = new double[n]; + boolean continueLinsten = true; + + for(int i = 0; i < n; i++) numArr[i] = scan.nextInt(); + + while(continueLinsten) { + try { + int n1 = scan.nextInt(), n2 = scan.nextInt(); + System.out.println(ArrayUtils.findMax(numArr, n1, n2)); + } + catch (IllegalArgumentException e) { + System.out.println(e); + } + catch (Exception e) { + continueLinsten = false; + } + } + scan.close(); + + try { + System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class)); + } catch (Exception e1) { + + } + } +} diff --git a/PTA/ProblemSet06/Problem06/Main.java b/PTA/ProblemSet06/Problem06/Main.java new file mode 100644 index 0000000..6dd8c29 --- /dev/null +++ b/PTA/ProblemSet06/Problem06/Main.java @@ -0,0 +1,91 @@ +package ProblemSet06.Problem06; + +import java.util.Scanner; +import java.util.NoSuchElementException; + +class IllegalNameException extends RuntimeException { + private static final long serialVersionUID = 3229322801946529935L; + + public IllegalNameException() { + super(); + } + + public IllegalNameException(String msg) { + super(msg); + } + +} + +class IllegalScoreException extends Exception{ + private static final long serialVersionUID = 1059038683602760667L; + + public IllegalScoreException() { + super(); + } + + public IllegalScoreException(String msg) { + super(msg); + } + +} + +class Student { + private String name; + private int score; + + public String getName() { + return name; + } + + public void setName(String name) { + if(Character.isDigit(name.charAt(0))) throw new IllegalNameException("the first char of name must not be digit, name=" + name); + + this.name = name; + } + + public int getScore() { + return score; + } + + public void setScore(int score) { + this.score = score; + } + + public String toString() { + return "Student [name=" + name + ", score=" + score + "]"; + } + + public int addScore(int score) throws IllegalScoreException { + int tmpScore = this.score + score; + if(tmpScore < 0 || tmpScore > 100) throw new IllegalScoreException("score out of range, score=" + tmpScore); + + this.score = tmpScore; + return this.score; + } + +} + +public class Main { + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + + while(true) { + String cmd = scan.nextLine(); + if ("new".equals(cmd)) { + try { + String[] sData = scan.nextLine().split(" "); + if(sData.length != 2) throw new NoSuchElementException(); + + Student stu = new Student(); + stu.setName(sData[0]); + stu.addScore(Integer.parseInt(sData[1])); + System.out.println(stu); + } catch (Exception e) { + System.out.println(e); + } + } else break; + } + scan.close(); + System.out.println("scanner closed"); + } +} -- Gitee From 46e2e9d978033a7bf0be84bf37231c394cdd48a9 Mon Sep 17 00:00:00 2001 From: Samler <15181536@qq.com> Date: Wed, 25 Nov 2020 16:20:56 +0800 Subject: [PATCH 4/9] update README.md --- PTA/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/PTA/README.md b/PTA/README.md index 0d75bf9..fd51f4e 100644 --- a/PTA/README.md +++ b/PTA/README.md @@ -17,6 +17,17 @@ - [7-3 jmu-Java-03面向对象基础-03-形状](./ProblemSet04/Problem03/Main.java) - [7-4 jmu-Java-03面向对象基础-05-覆盖](./ProblemSet04/Problem04/Main.java) - [7-5 jmu-Java-03面向对象-06-继承覆盖综合练习-Person、Student、Employee、Company](./ProblemSet04/Problem05/Main.java) +- 实验05 + - [7-1 jmu-Java-03面向对象基础-01-构造函数与toString](./ProblemSet05/Problem01/Main.java) + - [7-2 jmu-Java-03面向对象基础-02-构造函数与初始化块](./ProblemSet05/Problem02/Main.java) + - [7-3 jmu-Java-03面向对象基础-03-形状](./ProblemSet05/Problem03/Main.java) + - [7-4 jmu-Java-03面向对象基础-05-覆盖](./ProblemSet05/Problem04/Main.java) + - [7-5 jmu-Java-03面向对象-06-继承覆盖综合练习-Person、Student、Employee、Company](./ProblemSet05/Problem05/Main.java) +- 实验06 + - [7-1 消失的车](./ProblemSet06/Problem01/Main.java) + - [7-2 判断回文](./ProblemSet06/Problem02/Main.java) + - [7-3 我是升旗手](./ProblemSet06/Problem03/Main.java) + - 天梯题集(贡献者:[@small_lin168](https://gitee.com/small_lin168)) - [7-2 比较大小](./Tianti/Problem02/Main.java) -- Gitee From 7d4f2ca4bffbac01449e671f9368ff345eacefe6 Mon Sep 17 00:00:00 2001 From: Samler <15181536@qq.com> Date: Wed, 25 Nov 2020 16:22:46 +0800 Subject: [PATCH 5/9] update README.md --- PTA/README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/PTA/README.md b/PTA/README.md index fd51f4e..a1a440c 100644 --- a/PTA/README.md +++ b/PTA/README.md @@ -18,15 +18,16 @@ - [7-4 jmu-Java-03面向对象基础-05-覆盖](./ProblemSet04/Problem04/Main.java) - [7-5 jmu-Java-03面向对象-06-继承覆盖综合练习-Person、Student、Employee、Company](./ProblemSet04/Problem05/Main.java) - 实验05 - - [7-1 jmu-Java-03面向对象基础-01-构造函数与toString](./ProblemSet05/Problem01/Main.java) - - [7-2 jmu-Java-03面向对象基础-02-构造函数与初始化块](./ProblemSet05/Problem02/Main.java) - - [7-3 jmu-Java-03面向对象基础-03-形状](./ProblemSet05/Problem03/Main.java) - - [7-4 jmu-Java-03面向对象基础-05-覆盖](./ProblemSet05/Problem04/Main.java) - - [7-5 jmu-Java-03面向对象-06-继承覆盖综合练习-Person、Student、Employee、Company](./ProblemSet05/Problem05/Main.java) + - [7-1 消失的车](./ProblemSet05/Problem01/Main.java) + - [7-2 判断回文](./ProblemSet05/Problem02/Main.java) + - [7-3 我是升旗手](./ProblemSet05/Problem03/Main.java) - 实验06 - - [7-1 消失的车](./ProblemSet06/Problem01/Main.java) - - [7-2 判断回文](./ProblemSet06/Problem02/Main.java) - - [7-3 我是升旗手](./ProblemSet06/Problem03/Main.java) + - [7-1 jmu-Java-04面向对象进阶-01-接口-Comparable](./ProblemSet06/Problem01/Main.java) + - [7-2 jmu-Java-04面向对象进阶--02-接口-Comparator](./ProblemSet06/Problem02/Main.java) + - [7-3 jmu-Java-06异常-01-常见异常](./ProblemSet06/Problem03/Main.java) + - [7-4 jmu-Java-06异常-02-使用异常机制处理异常输入](./ProblemSet06/Problem04/Main.java) + - [7-5 jmu-Java-06异常-03-throw与throws](./ProblemSet06/Problem05/Main.java) + - [7-6 jmu-Java-06异常-04-自定义异常(综合)](./ProblemSet06/Problem06/Main.java) - 天梯题集(贡献者:[@small_lin168](https://gitee.com/small_lin168)) -- Gitee From 3c485128c5d0bcc7e587c5a7d715976a1ea22af5 Mon Sep 17 00:00:00 2001 From: Samler <15181536@qq.com> Date: Wed, 25 Nov 2020 16:24:32 +0800 Subject: [PATCH 6/9] rename PTA/ProblemSet03/Problem04/Main04.java to PTA/ProblemSet03/Problem04/Main.java. --- PTA/ProblemSet03/Problem04/{Main04.java => Main.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename PTA/ProblemSet03/Problem04/{Main04.java => Main.java} (94%) diff --git a/PTA/ProblemSet03/Problem04/Main04.java b/PTA/ProblemSet03/Problem04/Main.java similarity index 94% rename from PTA/ProblemSet03/Problem04/Main04.java rename to PTA/ProblemSet03/Problem04/Main.java index 773152d..85f6476 100644 --- a/PTA/ProblemSet03/Problem04/Main04.java +++ b/PTA/ProblemSet03/Problem04/Main.java @@ -4,7 +4,7 @@ import java.util.Scanner; import java.util.Arrays; import java.util.Comparator; -public class Main04 { +public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int id_len = Integer.parseInt(scan.nextLine()); -- Gitee From 2530d775619022d4824731e1e339806e05f10b04 Mon Sep 17 00:00:00 2001 From: Samler <15181536@qq.com> Date: Wed, 25 Nov 2020 16:25:10 +0800 Subject: [PATCH 7/9] rename PTA/ProblemSet02/Problem02/Main02.java to PTA/ProblemSet02/Problem02/Main.java. --- PTA/ProblemSet02/Problem02/{Main02.java => Main.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename PTA/ProblemSet02/Problem02/{Main02.java => Main.java} (88%) diff --git a/PTA/ProblemSet02/Problem02/Main02.java b/PTA/ProblemSet02/Problem02/Main.java similarity index 88% rename from PTA/ProblemSet02/Problem02/Main02.java rename to PTA/ProblemSet02/Problem02/Main.java index 0a63f2a..5a94f1e 100644 --- a/PTA/ProblemSet02/Problem02/Main02.java +++ b/PTA/ProblemSet02/Problem02/Main.java @@ -2,7 +2,7 @@ package ProblemSet02.Problem02; import java.util.Scanner; -public class Main02 { +public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); -- Gitee From 72ceb8304c5c6ae7ed920113161f1a34e52f6cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9E=97=E5=A4=B4=E5=8F=91=E4=B8=8D=E4=BC=9A?= =?UTF-8?q?=E6=B8=85=E9=9B=B6?= <1448801212@qq.com> Date: Thu, 3 Dec 2020 18:16:52 +0800 Subject: [PATCH 8/9] =?UTF-8?q?!13=20=E5=A2=9E=E5=8A=A0pta01=2008=2009=20*?= =?UTF-8?q?=20update=20PTA/Tianti/Problem09/Main.java.=20*=20update=20PTA/?= =?UTF-8?q?Tianti/Problem08/Main.java.=20*=20update=20PTA/Tianti/Problem01?= =?UTF-8?q?/Main.java.=20*=20add=20PTA/Tianti/Problem09/Main.java.=20*=20a?= =?UTF-8?q?dd=20PTA/Tianti/Problem08/Main.java.=20*=20add=20PTA/Tianti/Pro?= =?UTF-8?q?blem01/Main.java.=20*=20=E6=96=B0=E5=BB=BA=20Problem09=20*=20?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Problem08=20*=20=E6=96=B0=E5=BB=BA=20Probl?= =?UTF-8?q?em01=20*=20!12=20=E6=9B=B4=E6=96=B0PTA=E4=BD=9C=E4=B8=9A=20*=20?= =?UTF-8?q?update=20EXP/Exp06/README.md.=20*=20update=20README.md.=20*=20!?= =?UTF-8?q?10=20Update=20Exp06=20source=20code=20*=20!8=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=A4=A9=E6=A2=AF=E9=A2=98=E9=9B=86=20=E6=9D=A5?= =?UTF-8?q?=E8=87=AA=E8=B4=A1=E7=8C=AE=E8=80=85[@small=5Flin168]=20*=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20PTA/tianti=20*=20!5=207-?= =?UTF-8?q?8=20=E6=9F=A5=E9=AA=8C=E8=BA=AB=E4=BB=BD=E8=AF=81=20(15?= =?UTF-8?q?=E5=88=86)=20*=20!3=20add=20PTA/tianti.=20*=20add=20PTA/tianti.?= =?UTF-8?q?=20*=20!2=20update=20README.md=20*=20update=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PTA/Tianti/Problem01/.keep | 0 PTA/Tianti/Problem01/Main.java | 67 ++++++++++++++++++++++++++++++++++ PTA/Tianti/Problem08/.keep | 0 PTA/Tianti/Problem08/Main.java | 42 +++++++++++++++++++++ PTA/Tianti/Problem09/.keep | 0 PTA/Tianti/Problem09/Main.java | 36 ++++++++++++++++++ 6 files changed, 145 insertions(+) create mode 100644 PTA/Tianti/Problem01/.keep create mode 100644 PTA/Tianti/Problem01/Main.java create mode 100644 PTA/Tianti/Problem08/.keep create mode 100644 PTA/Tianti/Problem08/Main.java create mode 100644 PTA/Tianti/Problem09/.keep create mode 100644 PTA/Tianti/Problem09/Main.java diff --git a/PTA/Tianti/Problem01/.keep b/PTA/Tianti/Problem01/.keep new file mode 100644 index 0000000..e69de29 diff --git a/PTA/Tianti/Problem01/Main.java b/PTA/Tianti/Problem01/Main.java new file mode 100644 index 0000000..41bbe8d --- /dev/null +++ b/PTA/Tianti/Problem01/Main.java @@ -0,0 +1,67 @@ +package Tianti.Problem01; + +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + + //输入完n之后将光标移到一下行 + sc.nextLine(); + int a, b; + + String str=sc.nextLine(); +// System.out.println("This is:"+str); + String[] split = str.split(" "); + String s = split[0]; + //获取分子 + a = Integer.parseInt(s.substring(0, s.indexOf('/'))); + //获取分母 + b = Integer.parseInt(s.substring(s.indexOf('/') + 1)); + int x, y, common; + + common = gcd(a, b); + a /= common; + b /= common; + + for (int i = 1; i < n; i++) { + s = split[i]; + x = Integer.parseInt(s.substring(0, s.indexOf('/'))); + y = Integer.parseInt(s.substring(s.indexOf('/') + 1)); + + common = y * b / gcd(y, b); + + a *= common / b; + x *= common / y; + + a += x; + b = common; + + common = gcd(a, b); + a /= common; + b /= common; + + } + + if(a / b != 0) { + if(a % b != 0) + System.out.println(a / b + " " + a % b + "/" + b); + else + System.out.println(a / b); + } else { + if(a % b != 0) + System.out.println(a % b + "/" + b); + else + System.out.println(0); + } + } + + private static int gcd(int a, int b) { + if(b==0){ + return a; + }else{ + return gcd(b,a%b); + } + } +} \ No newline at end of file diff --git a/PTA/Tianti/Problem08/.keep b/PTA/Tianti/Problem08/.keep new file mode 100644 index 0000000..e69de29 diff --git a/PTA/Tianti/Problem08/Main.java b/PTA/Tianti/Problem08/Main.java new file mode 100644 index 0000000..c6abf00 --- /dev/null +++ b/PTA/Tianti/Problem08/Main.java @@ -0,0 +1,42 @@ +package Tianti.Problem08; + +import java.util.*; + +public class Pta8 { + //存储后序遍历结点 + private static Vector post = new Vector<>(); + //存储中序遍历结点 + private static Vector in = new Vector<>(); + //有序/LinkedHashMap + private static TreeMap level = new TreeMap<>(); + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + for(int i = 0; i end)return; + int i = start; + while(i < end && in.get(i) != post.get(root)){ + i++; + } + level.put(index,post.get(root));//根 + pre(root - 1 - end + i, start, i - 1, 2 * index + 1);//左 + pre(root - 1, i + 1, end, 2 * index + 2);//右 + } +} \ No newline at end of file diff --git a/PTA/Tianti/Problem09/.keep b/PTA/Tianti/Problem09/.keep new file mode 100644 index 0000000..e69de29 diff --git a/PTA/Tianti/Problem09/Main.java b/PTA/Tianti/Problem09/Main.java new file mode 100644 index 0000000..ee6c6d2 --- /dev/null +++ b/PTA/Tianti/Problem09/Main.java @@ -0,0 +1,36 @@ +package Tianti.Problem09; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Pta9 { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String str = reader.readLine(); + //设置一个NN的二维数组 + int arr_i[][] = new int[str.length()][str.length()]; + int res_count =0; + for(int i=0;i=2){ + if(str.charAt(i)==str.charAt(j)&&arr_i[j+1][i-1]>0){ + arr_i[j][i] = arr_i[j+1][i-1]+2; + } + } + } + } + for(int i=0;i Date: Thu, 3 Dec 2020 18:19:07 +0800 Subject: [PATCH 9/9] update README --- PTA/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PTA/README.md b/PTA/README.md index a1a440c..a876202 100644 --- a/PTA/README.md +++ b/PTA/README.md @@ -31,12 +31,15 @@ - 天梯题集(贡献者:[@small_lin168](https://gitee.com/small_lin168)) + - [7-1 N个数求和](./Tianti/Problem01/Main.java) - [7-2 比较大小](./Tianti/Problem02/Main.java) - [7-3 计算指数](./Tianti/Problem03/Main.java) - [7-4 计算阶乘和](./Tianti/Problem04/Main.java) - [7-5 简单题](./Tianti/Problem05/Main.java) - [7-6 跟奥巴马一起画方块](./Tianti/Problem06/Main.java) - [7-7 查验身份证](./Tianti/Problem07/Main.java) + - [7-10 树的遍历](./Tianti/Problem08/Main.java) + - [7-12 最长对称子串](./Tianti/Problem09/Main.java) ### 讨论和建议 如果大家在查看过程中发现错误或不足之处,欢迎大家在[Issues](https://gitee.com/Samler/java-work/issues)中发表自己的见解,也欢迎大家在[Issues](https://gitee.com/Samler/java-work/issues)中进行讨论。 -- Gitee