diff --git a/README.md b/README.md index 27df5ebe65f2aeb31dba3ce3d49dcfc69340d96e..37a780a304f909ee4948d91aaee9540de52dd4e5 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ #### Tips 若需要上传其他有帮助的项目或者文件请在shared分支进行操作,否则一律不允许通过哦,谢谢配合!!! +>>>>>>> master 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 0000000000000000000000000000000000000000..133b6e30d79db47164ade433bc682c8b3b747ab6 --- /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/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 0000000000000000000000000000000000000000..9063eda7f5bf5be4ece1edc5b7fb36ccec53f24c --- /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"); + } + } + +} 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 0000000000000000000000000000000000000000..77780a5a119cc6b68f7434010e14a7f55d082972 --- /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)); + } + +} 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 0000000000000000000000000000000000000000..492966cbd0ddacb65549e5fff1a71b93f9120de3 --- /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 0000000000000000000000000000000000000000..114280751421b42590a213a57bfada14cd6709cb --- /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/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 0000000000000000000000000000000000000000..b6a08387819419be28363aa115e96ce596d5cd3d --- /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 0000000000000000000000000000000000000000..996634a1b025b45bc91b0583e70f5ac7de80a7b2 --- /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 0000000000000000000000000000000000000000..d360ed6f3d3f646325df346cfbb566a704f08605 --- /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,119 @@ +import java.util.*; + +public class Main { + + static String str=""; + + class Node { + int data; + Node leftChild; + Node rightChild; + + public Node(int idata) { + data = idata; + } + } + + // 根节点 + private Node root; + + // 接受中序遍历数组和后序遍历数组,进入递归方法 + Node reCreatTree(int[] mid, int[] last) { + root = reCreate(mid, 0, mid.length - 1, last, 0, last.length - 1); + return root; + } + + // 参数依次为中序遍历数组,起始点,结束点;后序遍历数组,起始点,结束点 + Node reCreate(int[] mid, int midStrat, int midEnd, int[] last, int lastStart, int lastEnd) { + // 防止前后交叉导致已选过的数值重复选中 + if (lastStart > lastEnd) { + return null; + } + // 防止数组越界 + if (lastStart < 0 || lastEnd < 0 || midStrat < 0 || midEnd < 0) { + return null; + } + // 给所选节点赋值 + 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; + } + + // 获得所选子树的根节点在中序数组中的下标 + 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; + } + } + return index; + } + + // 输出树 + 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= 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