From 5ef6690fcee267cec9423a6ede92a1fd74e68741 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, 12 Nov 2020 08:27:14 +0800 Subject: [PATCH 01/10] add text.txt. --- text.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 text.txt diff --git a/text.txt b/text.txt new file mode 100644 index 0000000..e69de29 -- Gitee From 514e81a7d88acaf19ed92755a3951c55a3d09148 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, 12 Nov 2020 08:28:28 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?xt.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 text.txt diff --git a/text.txt b/text.txt deleted file mode 100644 index e69de29..0000000 -- Gitee From d6efdf45fbb54f742b019eaddaad3956d34d507d 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, 12 Nov 2020 08:31:37 +0800 Subject: [PATCH 03/10] update README.md. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index de2573c..ccf7032 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,10 @@ #### 介绍 厦理的PTA的题目集~ + +#### Tips: +- 大家可以发布自己的项目文件 +- 我会不定时的为大家审核排查,若有精选项目我会合并起来 + +#### Last +希望我的gitee大家会喜欢,我的出发点就是为了备份学习资料,一起共同进步~ \ No newline at end of file -- Gitee From 60780c2cb0ffb72df1e5d7e33b8efea3458ceb1e 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, 12 Nov 2020 08:33:27 +0800 Subject: [PATCH 04/10] add text.txt. --- text.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 text.txt diff --git a/text.txt b/text.txt new file mode 100644 index 0000000..e69de29 -- Gitee From 1b76c592d3c63e7fd89e39e7d074d801f9c9e9cf 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, 12 Nov 2020 08:33:44 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?xt.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 text.txt diff --git a/text.txt b/text.txt deleted file mode 100644 index e69de29..0000000 -- Gitee From ce85a9d101cde8fb395d8f9a5e961c4324f93f2c 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, 12 Nov 2020 08:39:14 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?xt.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 text.txt diff --git a/text.txt b/text.txt deleted file mode 100644 index e69de29..0000000 -- Gitee From 9e7b435ef262e6eac87ab836aa4b7b8a71705b0b 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, 12 Nov 2020 15:42:53 +0800 Subject: [PATCH 07/10] add Tianti. --- .../Pta1.java" | 54 +++++++++++++ .../Pta6.java" | 26 ++++++ .../Pta7.java" | 49 ++++++++++++ .../Pta8.java" | 79 +++++++++++++++++++ .../Pta9.java" | 41 ++++++++++ 5 files changed, 249 insertions(+) create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta1.java" create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta6.java" create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta7.java" create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta8.java" create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta9.java" diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta1.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta1.java" new file mode 100644 index 0000000..133b6e3 --- /dev/null +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta1.java" @@ -0,0 +1,54 @@ +package tianti; + +import java.util.Scanner; + +public class Pta1 { + + static int gcd(int a, int b) { + if (b == 0) + return a; + else + return gcd(b, a % b); + } + + static int lcm(int a, int b) { + return a * b / gcd(a, b); + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int a, b, ta = 0, tb = 0; + for (int i = 1; i <= n; i++) { + String str = sc.next(); + a = Integer.parseInt(str.split("/")[0]); + b = Integer.parseInt(str.split("/")[1]); + if (i == 1) { + ta = a; + tb = b; + } else { + int sb; + sb = lcm(b, tb);// С + // ϲ + ta = sb / tb * ta + sb / b * a; + tb = sb; + } + // + int g = gcd(Math.abs(ta), Math.abs(tb)); + ta = ta / g; + tb = tb / g; + } + if (ta == 0 || Math.abs(ta) >= tb) { + System.out.print(ta / tb + " "); + if (ta % tb == 0) { + System.out.println(); + } else { + System.out.println("" + (Math.abs(ta) % tb) + "/" + tb + ""); + } + } else { + System.out.println("" + ta + "/" + tb + ""); + } + } + +} diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta6.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta6.java" new file mode 100644 index 0000000..b6a0838 --- /dev/null +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta6.java" @@ -0,0 +1,26 @@ +package tianti; + +import java.util.Scanner; + +public class Pta6 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + double n = sc.nextInt(); // Nַ + String s = sc.next(); // ַʽ + if (3 <= n && n <= 21) { + double h = n / 2; // ߶ + int x = (int) (n / 2); // + double y = h - x; + if (y >= 0.5) { + h++; + } + for (int i = 0; i < (int) h; i++) { //ͨ߶ӡ + for (int j = 0; j < n; j++) { //ͨӡ + System.out.print(s); + } + System.out.println(); + } + } + + } +} diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta7.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta7.java" new file mode 100644 index 0000000..996634a --- /dev/null +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta7.java" @@ -0,0 +1,49 @@ +package tianti; + +import java.util.Scanner; + +public class Pta7 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + // Լ + // 350322111122334455 + Scanner sc = new Scanner(System.in); + String[] Z = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; + char[] M = new char[] { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' }; + //Ȩ + int[] pow = new int[] { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 }; + + int N = sc.nextInt(); + char[][] id_spilt = new char[N][18]; + int allpassed = 1; + // N֤ά + for (int i = 0; i < N; i++) { + String id_card = sc.next(); + for (int j = 0; j < 18; j++) { + id_spilt[i][j] = Character.valueOf(id_card.charAt(j)); + } + } + // ж + for (int i = 0; i < N; i++) { + int z = 0; + for (int j = 0; j < 17; j++) { + z += ((id_spilt[i][j]) - '0') * pow[j]; + } + //ȡģ + z %= 11; + if (M[z] != id_spilt[i][17]) { + allpassed = 0; + for (int k = 0; k < 18; k++) { + System.out.print(id_spilt[i][k]); + } + System.out.println(); + } + } + if (allpassed == 1) { + System.out.println("All passed"); + } + } + +} diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta8.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta8.java" new file mode 100644 index 0000000..6dab4b2 --- /dev/null +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta8.java" @@ -0,0 +1,79 @@ +package tianti; + +public class Pta8 { + + int findPosInInOrder(String str,String in,int position){ + char c = str.charAt(position); + int length = in.length(); + for(int i=0;i= i; j--) { + String temp = str.substring(i, j); + if (symmetric(temp) && temp.length() >= substr.length()) + substr = temp; + } + } + return substr; + } +} \ No newline at end of file -- Gitee From 24d5c4d72896cc1b05e0052befdd25cd704d955f 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, 12 Nov 2020 16:10:31 +0800 Subject: [PATCH 08/10] =?UTF-8?q?add=20=E5=A4=A9=E6=A2=AF=E9=A2=98?= =?UTF-8?q?=E9=9B=86=EF=BC=881=EF=BC=89/Pta2.java.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pta2.java" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta2.java" diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta2.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta2.java" new file mode 100644 index 0000000..9063eda --- /dev/null +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta2.java" @@ -0,0 +1,24 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc=new Scanner(System.in); + int N=3; + int[] sort_result=new int[N]; + for(int i =0;i"); + } + } + +} -- Gitee From de1219d70b07f6758483cf3ffc7d8a2b04800664 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, 12 Nov 2020 16:12:00 +0800 Subject: [PATCH 09/10] =?UTF-8?q?add=20=E5=A4=A9=E6=A2=AF=E9=A2=98?= =?UTF-8?q?=E9=9B=86=EF=BC=881=EF=BC=89/Pta3.java.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pta3.java" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta3.java" diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta3.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta3.java" new file mode 100644 index 0000000..77780a5 --- /dev/null +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta3.java" @@ -0,0 +1,13 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc=new Scanner(System.in); + int N=sc.nextInt(); + System.out.println("2^"+N+" = "+(int)Math.pow(2, N)); + } + +} -- Gitee From e40c37691bb6cf3183e754f019be247cfee31a4a 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, 12 Nov 2020 16:16:20 +0800 Subject: [PATCH 10/10] alter --- .../Pta4.java" | 27 +++ .../Pta5.java" | 9 + .../Pta8.java" | 174 +++++++++++------- 3 files changed, 143 insertions(+), 67 deletions(-) create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta4.java" create mode 100644 "\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta5.java" diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta4.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta4.java" new file mode 100644 index 0000000..492966c --- /dev/null +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta4.java" @@ -0,0 +1,27 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); + System.out.println(fib(N)); + } + + public static int fib(int N) { + int temp = 1; + int sum = 0; + for (int i = 1; i <= N; i++) { + if (N == 0) { + sum = 1; + } else { + temp *= i; + sum += temp; + } + } + return sum; + } + +} diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta5.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta5.java" new file mode 100644 index 0000000..1142807 --- /dev/null +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta5.java" @@ -0,0 +1,9 @@ +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + System.out.println("This is a simple problem."); + } + +} diff --git "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta8.java" "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta8.java" index 6dab4b2..d360ed6 100644 --- "a/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta8.java" +++ "b/\345\244\251\346\242\257\351\242\230\351\233\206\357\274\2101\357\274\211/Pta8.java" @@ -1,79 +1,119 @@ -package tianti; +import java.util.*; -public class Pta8 { +public class Main { - int findPosInInOrder(String str,String in,int position){ - char c = str.charAt(position); - int length = in.length(); - for(int i=0;i lastEnd) { + return null; } - if(0==length){ - return; + // 防止数组越界 + if (lastStart < 0 || lastEnd < 0 || midStrat < 0 || midEnd < 0) { + return null; } - int index = findPosInInOrder(preOrder, inOrder,0); - String inOrder_left = inOrder.substring(0,index); - String inOrder_right = inOrder.substring(index+1); - - String preOrder_left = preOrder.substring(1,1+index); - String preOrder_right = preOrder.substring(index+1); - - postOrder(preOrder_left,inOrder_left,inOrder_left.length()); - postOrder(preOrder_right,inOrder_right,inOrder_right.length()); - - System.out.println(preOrder.charAt(0)); - + // 给所选节点赋值 + Node newNode = new Node(last[lastEnd]); + int index = IndexOfRootInMid(mid, newNode.data); + // 所选节点左子树的数量 + int leftNum = index - midStrat; + // 向左子树往下走 + newNode.leftChild = reCreate(mid, midStrat, index - 1, last, lastStart, lastStart + leftNum - 1); + // 向右子树往下走 + newNode.rightChild = reCreate(mid, index + 1, midEnd, last, lastStart + leftNum, lastEnd - 1); + // 返回节点 + return newNode; } - /** - * ֪ - * @param postOrder - * @param inOrder - * @param length - */ - void preOrder(String postOrder,String inOrder,int length){ - if(1==length){ - System.out.println(inOrder); - return; - } - if(0==length){ - return; + + // 获得所选子树的根节点在中序数组中的下标 + int IndexOfRootInMid(int[] mid, int rootData) { + int index = -1; + for (int i = 0; i < mid.length - 1; i++) { + if (mid[i] == rootData) { + index = i; + break; + } } - int index = findPosInInOrder(postOrder, inOrder,postOrder.length()-1); - String inOrder_left = inOrder.substring(0,index); - String inOrder_right = inOrder.substring(index+1); - - String postOrder_left = postOrder.substring(0,index); - String postOrder_right = postOrder.substring(index+1,postOrder.length()-1); - - System.out.println(postOrder.charAt(postOrder.length()-1)); - preOrder(postOrder_left,inOrder_left,inOrder_left.length()); - preOrder(postOrder_right,inOrder_right,inOrder_right.length()); - - - + return index; } - public static void main(String args[]){ - Pta8 order= new Pta8(); - String pre="ABDEC"; - String in="DBEAC"; - String post = "DEBCA"; - order.postOrder(pre, in, in.length()); // - - System.out.println("********************************"); - order.preOrder(post, in, in.length()); // + + // 输出树 + public void displayTree() { + Stack globalStack = new Stack(); + globalStack.push(root); + int nBlanks = 32; + boolean isRowEmpty = false; + while (isRowEmpty == false) { + Stack localStack = new Stack(); + isRowEmpty = true; + + while (globalStack.isEmpty() == false) { + Node temp = (Node) globalStack.pop(); + if (temp != null) { +// System.out.print(temp.data+" "); + str+=temp.data; + localStack.push(temp.leftChild); + localStack.push(temp.rightChild); + if (temp.leftChild != null || temp.rightChild != null) + isRowEmpty = false; + } else { + localStack.push(null); + localStack.push(null); + } + + } + nBlanks /= 2; + while (localStack.isEmpty() == false) + globalStack.push(localStack.pop()); + } } + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); +// System.out.println("请输入N:"); + int N = sc.nextInt(); + int[] preOrder = new int[N]; + int[] inOrder = new int[N]; + int[] postOrder = new int[N]; +// System.out.println("请输入后序遍历:"); + for (int i = 0; i < N; i++) { + postOrder[i] = sc.nextInt(); + } +// System.out.println("请输入中序遍历:"); + for (int i = 0; i < N; i++) { + inOrder[i] = sc.nextInt(); + } + Main tree = new Main(); + tree.reCreatTree(inOrder, postOrder); + tree.displayTree(); +// System.out.println(str); + for(int i=0;i