diff --git a/GE_Migrating_data/lib/HistorianServiceAPI.jar b/GE_Migrating_data/lib/HistorianServiceAPI.jar new file mode 100644 index 0000000..f7d0785 Binary files /dev/null and b/GE_Migrating_data/lib/HistorianServiceAPI.jar differ diff --git a/GE_migate/pom.xml b/GE_migate/pom.xml new file mode 100644 index 0000000..38209fc --- /dev/null +++ b/GE_migate/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + com.cqu.ge + GE_migate + 1.0-SNAPSHOT + + + junit + junit + RELEASE + compile + + + + com.cqu + ge + 1.0.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 8 + 8 + + + \ No newline at end of file diff --git a/GE_migate/src/main/java/OracleODBC.java b/GE_migate/src/main/java/OracleODBC.java new file mode 100644 index 0000000..07ae907 --- /dev/null +++ b/GE_migate/src/main/java/OracleODBC.java @@ -0,0 +1,157 @@ + +import java.io.FileInputStream; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +public class OracleODBC { + private static Connection conn; + private static PreparedStatement ps; + private static ResultSet rs; + private static String odbc_driver; + private static String odbc_url; + private static String username; + private static String password; + + public static void main(String[] args) { + // 测试 + String sql = "select * from emp"; + System.out.println("ODBC************"); + ResultSet rst = OracleODBC.executeQuery(sql, null); + try { + while(rst.next()){ + System.out.println(rst.getString("ename")); + } + } catch (Exception e) { + e.printStackTrace(); + }finally{ + OracleODBC.close(OracleODBC.getConn(),OracleODBC.getPs(),rst); + } + } + + + static{ + try { + Map map = get(); + odbc_driver = map.get("odbc_driver"); + odbc_url = map.get("odbc_url"); + username = map.get("username"); + password = map.get("password"); + + Class.forName(odbc_driver); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + //初始化变量 + public static Map get(){ + Properties pp = new Properties(); + FileInputStream fis = null; + Map map = new HashMap(); + try { + fis = new FileInputStream("dbinfor.properties");//dbinfor.properties在工程路径下面 + pp.load(fis); + odbc_driver = pp.getProperty("odbc_driver"); + odbc_url = pp.getProperty("odbc_url"); + username = pp.getProperty("username"); + password = pp.getProperty("password"); + map.put("odbc_driver", odbc_driver); + map.put("odbc_url", odbc_url); + map.put("username", username); + map.put("password", password); + + } catch (Exception e) { + e.printStackTrace(); + } + return map; + } + + //增删改方法 + public static void executeUpdate(String sql,String []parameters){ + try { + conn = DriverManager.getConnection(odbc_url, username, password); + ps = conn.prepareStatement(sql); + if(parameters!=null){ + for(int i=0;i= 2) { + dp[i] = Math.max(dp[i], dp[i - 2] + nums[i - 1]); + } + if (i >= 3) { + dp[i] = Math.max(dp[i], dp[i - 3] + nums[i - 1]); + } + if (i >= 4 && i != 5) { + dp[i] = Math.max(dp[i], dp[i - 4] + nums[i - 1]); + } + } + + System.out.println(dp[n]); + } + + public void sovle1(int[] nums) { + int n = nums.length; + int[] dp = new int[n];//[不选,选] + dp[0]=nums[0]; + + for (int i = 1; i < n; i++) { + if (i >= 3) { + dp[i] = Math.max(dp[i - 3] + nums[i],dp[i - 1]); + } else { + dp[i]=Math.max(dp[i-1],nums[i]); + } + } + + System.out.println(dp[n-1]); + } + + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[] a = new int[n]; + for (int i = 0; i < n; i++) { + a[i] = sc.nextInt(); + } + sc.close(); + + int[] dp = new int[n + 1]; + + for (int i = 1; i <= n; i++) { + dp[i] = dp[i - 1]; + if (i >= 2) { + dp[i] = Math.max(dp[i], dp[i - 2] + a[i - 1]); + } + if (i >= 3) { + dp[i] = Math.max(dp[i], dp[i - 3] + a[i - 1]); + } + if (i >= 4 && i != 5) { + dp[i] = Math.max(dp[i], dp[i - 4] + a[i - 1]); + } + } + + System.out.println(dp[n]); + } + +} diff --git a/Leecode/src/main/java/com/markilue/leecode/interview/meituan/Question3.java b/Leecode/src/main/java/com/markilue/leecode/interview/meituan/Question3.java new file mode 100644 index 0000000..5f61de1 --- /dev/null +++ b/Leecode/src/main/java/com/markilue/leecode/interview/meituan/Question3.java @@ -0,0 +1,66 @@ +package com.markilue.leecode.interview.meituan; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.Scanner; + +/** + * @BelongsProject: Leecode + * @BelongsPackage: com.markilue.leecode.interview.meituan + * @Author: marklue + * @CreateTime: 2023/3/25 19:18 + * @Description: TODO + * @Version: 1.0 + */ +public class Question3 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int m = sc.nextInt(); + int n = sc.nextInt(); + int[] weight = new int[m]; + int[] bag = new int[n]; + int max = 0; + for (int i = 0; i < weight.length; i++) { + weight[i] = sc.nextInt(); + } + + for (int i = 0; i < n; i++) { + bag[i] = sc.nextInt(); + max = Math.max(max, bag[i]); + } + int[] dp = new Question3().sovle(weight, max); + for (int i : bag) { + System.out.print(dp[i] + " "); + } + } + + @Test + public void test() { + int[] nums = {5,2,1,4,2}; + sovle(nums, 15); + } + + public int[] sovle(int[] weight, int bag) { + int[][] dp = new int[weight.length][bag + 1]; + + for (int i = 0; i < dp[0].length; i++) { + if (i >= weight[0] * weight[0]) dp[0][i] = 1; + } + for (int i = 1; i < dp.length; i++) { + for (int j = 1; j < dp[0].length; j++) { + int weight1 = weight[i] * weight[i]; + if (weight1 > j) dp[i][j]=dp[i-1][j]; + else dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - weight1] + 1); + } + } +// for (int i = 0; i < dp.length; i++) { +// System.out.println(Arrays.toString(dp[i])); +// } + return dp[dp.length-1]; + } + + + +} diff --git a/Leecode/src/main/java/com/markilue/leecode/interview/meituan/Question4.java b/Leecode/src/main/java/com/markilue/leecode/interview/meituan/Question4.java new file mode 100644 index 0000000..386ca96 --- /dev/null +++ b/Leecode/src/main/java/com/markilue/leecode/interview/meituan/Question4.java @@ -0,0 +1,49 @@ +package com.markilue.leecode.interview.meituan; + +import java.util.Scanner; + +/** + * @BelongsProject: Leecode + * @BelongsPackage: com.markilue.leecode.interview.meituan + * @Author: marklue + * @CreateTime: 2023/3/25 20:24 + * @Description: TODO + * @Version: 1.0 + */ +public class Question4 { + + + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int k = sc.nextInt(); + int[] a = new int[n + 1]; + for (int i = 1; i <= n; i++) { + a[i] = sc.nextInt(); + } + int[][][] dp = new int[n + 1][k + 1][2]; + // 初始化 + for (int j = 0; j <= k; j++) { + dp[1][j][0] = 0; + dp[1][j][1] = a[1]; + } + // 状态转移 + for (int i = 2; i <= n; i++) { + for (int j = 0; j <= k; j++) { + dp[i][j][0] = Math.max(dp[i - 1][j][0], dp[i - 1][j][1]); + if (j > 0) { + dp[i][j][1] = Math.max(dp[i - 1][j - 1][1] + a[i], dp[i - 1][j][0] + a[i]); + } else { + dp[i][j][1] = dp[i - 1][j][0] + a[i]; + } + } + } + // 取最大值 + int ans = 0; + for (int j = 0; j <= k; j++) { + ans = Math.max(ans, Math.max(dp[n][j][0], dp[n][j][1])); + } + System.out.println(ans); + } +} diff --git a/Leecode/src/main/java/com/markilue/leecode/listnode/selftry/DeleteDuplicates.java b/Leecode/src/main/java/com/markilue/leecode/listnode/selftry/DeleteDuplicates.java new file mode 100644 index 0000000..06f4af9 --- /dev/null +++ b/Leecode/src/main/java/com/markilue/leecode/listnode/selftry/DeleteDuplicates.java @@ -0,0 +1,54 @@ +package com.markilue.leecode.listnode.selftry; + +import com.markilue.leecode.listnode.ListNode; +import com.markilue.leecode.listnode.ListNodeUtils; +import org.junit.Test; + +public class DeleteDuplicates { + + @Test + public void test() { + ListNode root = ListNodeUtils.build(new int[]{1, 1, 2, 2}); + ListNodeUtils.print(deleteDuplicates(root)); + } + + + public ListNode deleteDuplicates(ListNode head) { + + ListNode fake = new ListNode(); + fake.next = head; + ListNode temp = head; + while (temp != null) { + if (temp.next != null && temp.val == temp.next.val) { + ListNode temp1 = temp.next; + while (temp1.next != null && temp1.val == temp1.next.val) { + temp1 = temp1.next; + } + temp.next = temp1.next; + } + temp = temp.next; + } + + return fake.next; + + } + + public ListNode deleteDuplicates1(ListNode head) { + if (head == null) { + return head; + } + + ListNode cur = head; + while (cur.next != null) { + if (cur.val == cur.next.val) { + cur.next = cur.next.next; + } else { + cur = cur.next; + } + } + + return head; + } + + +} diff --git a/Leecode/src/main/java/com/markilue/leecode/listnode/selftry/DeleteDuplicatesII.java b/Leecode/src/main/java/com/markilue/leecode/listnode/selftry/DeleteDuplicatesII.java new file mode 100644 index 0000000..9dbbd69 --- /dev/null +++ b/Leecode/src/main/java/com/markilue/leecode/listnode/selftry/DeleteDuplicatesII.java @@ -0,0 +1,52 @@ +package com.markilue.leecode.listnode.selftry; + + +import com.markilue.leecode.listnode.ListNode; +import com.markilue.leecode.listnode.ListNodeUtils; +import org.junit.Test; + +/** + * @BelongsProject: Leecode + * @BelongsPackage: com.markilue.leecode.listnode.selftry + * @Author: marklue + * @CreateTime: 2023/3/25 18:50 + * @Description: TODO 美团笔试 链表去重升级:把重复的也去掉 + * @Version: 1.0 + */ +public class DeleteDuplicatesII { + + @Test + public void test(){ + ListNode root = ListNodeUtils.build(new int[]{1, 1, 2,2,2}); + ListNodeUtils.print(deleteDuplicates(root)); + + } + + + public ListNode deleteDuplicates(ListNode head) { + + if (head == null) { + return head; + } + + ListNode fake = new ListNode(); + fake.next = head; + ListNode temp = fake; + while (temp.next != null) { + if (temp.next.next != null && temp.next.val == temp.next.next.val) { + ListNode temp1 = temp.next; + while (temp1.next != null && temp1.val == temp1.next.val) { + temp1 = temp1.next; + } + temp.next = temp1.next; + }else { + temp = temp.next; + } + + + } + + return fake.next; + + } +} diff --git a/TensorFlow_eaxmple/Model_train_test/703Test/703Connect.py b/TensorFlow_eaxmple/Model_train_test/703Test/703Connect.py new file mode 100644 index 0000000..fd51554 --- /dev/null +++ b/TensorFlow_eaxmple/Model_train_test/703Test/703Connect.py @@ -0,0 +1,25 @@ +import pyodbc + +# 定义连接字符串 +conn_str = ( + r"DRIVER=IhOLEDB.iHistorian.1;" + r"Persist Security Info=True;" + r"Mode=Read;" + r"server=192.168.9.8;" + r"uid=administrator;" + r"pwd=TES@ihistorian2018;" +) + +# 使用pyodbc连接数据库 +cnxn = pyodbc.connect(conn_str) + +# 执行SQL查询 +cursor = cnxn.cursor() +cursor.execute("select * from ihTags where tagname= [HN.DF.DF11.DF11_TC1].AIO.AN_Air_Supply_Pressure") + +# 处理结果集 +for row in cursor.fetchall(): + print(row) + +# 关闭连接 +cnxn.close() diff --git a/interview/RedCampus/src/main/java/com/markilue/interview/Question1.java b/interview/RedCampus/src/main/java/com/markilue/interview/Question1.java new file mode 100644 index 0000000..e8d23ba --- /dev/null +++ b/interview/RedCampus/src/main/java/com/markilue/interview/Question1.java @@ -0,0 +1,51 @@ +package com.markilue.interview; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Scanner; + +/** + * @BelongsProject: RedCampus + * @BelongsPackage: com.markilue.interview + * @Author: marklue + * @CreateTime: 2023/3/26 16:23 + * @Description: TODO + * @Version: 1.0 + */ +public class Question1 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = Integer.parseInt(sc.nextLine()); + char[] chars1 = sc.nextLine().toCharArray(); + new Question1().sovle(chars1); + + + } + + @Test + public void test(){ +// char a= (char)('d'-3); + char[] chars={'a','e','f'}; + sovle(chars); + } + + public void sovle(char[] chars) { + char[] result = new char[chars.length]; + HashMap map = new HashMap() {{ + put('a', 'x'); + put('b', 'y'); + put('c', 'z'); + }}; + for (int i = 0; i < chars.length; i++) { + + if (map.containsKey(chars[i])) { + result[i] = map.get(chars[i]); + } else { + result[i] = (char) (chars[i] - 3); + } + } + System.out.println(new String(result)); + } +} diff --git a/interview/RedCampus/src/main/java/com/markilue/interview/Question2.java b/interview/RedCampus/src/main/java/com/markilue/interview/Question2.java new file mode 100644 index 0000000..99ca56e --- /dev/null +++ b/interview/RedCampus/src/main/java/com/markilue/interview/Question2.java @@ -0,0 +1,52 @@ +package com.markilue.interview; + +import java.util.Scanner; + +/** + * @BelongsProject: RedCampus + * @BelongsPackage: com.markilue.interview + * @Author: marklue + * @CreateTime: 2023/3/26 16:36 + * @Description: TODO + * @Version: 1.0 + */ +public class Question2 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int time = sc.nextInt(); + + while (time-- > 0) { + int n = sc.nextInt(); + int k = sc.nextInt(); + int[] nums = new int[n]; + for (int i = 0; i < n; i++) { + nums[i] = sc.nextInt(); + } + + } + } + + /** + * 一次最多移动k个数 + * 计算有多少个乱序的 + * + * @param nums + * @param k + */ + public void sovle(int[] nums, int k) { + + int count = 0; + for (int i = 0; i < nums.length; i++) { + if ((i + 1) != nums[i]) { + count++; + } + } + if (count % k == 0) { + System.out.println(count / k); + } else { + System.out.println(count / k + 1); + } + + } +} diff --git a/interview/RedCampus/src/main/java/com/markilue/interview/Question3.java b/interview/RedCampus/src/main/java/com/markilue/interview/Question3.java new file mode 100644 index 0000000..d1d664e --- /dev/null +++ b/interview/RedCampus/src/main/java/com/markilue/interview/Question3.java @@ -0,0 +1,133 @@ +package com.markilue.interview; + +import org.junit.Test; + +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Scanner; + +/** + * @BelongsProject: RedCampus + * @BelongsPackage: com.markilue.interview + * @Author: marklue + * @CreateTime: 2023/3/26 16:50 + * @Description: TODO + * @Version: 1.0 + */ +public class Question3 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[] nums = new int[n]; + for (int i = 0; i < n; i++) { + nums[i] = sc.nextInt(); + } + int k = sc.nextInt();//操作的次数 + int[] left = new int[k]; + int[] right = new int[k]; + for (int i = 0; i < k; i++) { + left[i] = sc.nextInt() - 1;//-1变成索引 + } + for (int i = 0; i < k; i++) { + right[i] = sc.nextInt() - 1;//-1变成索引 + } + + + char[] deal = sc.next().toCharArray();//操作手段 + + + int[] dealNum = new int[k]; + for (int i = 0; i < k; i++) { + dealNum[i] = sc.nextInt(); + } + } + + public void test() { + Scanner sc = new Scanner(System.in); + int n = Integer.parseInt(sc.nextLine()); + String[] s = sc.nextLine().split(" "); + int[] nums = Arrays.stream(s).mapToInt(Integer::parseInt).toArray(); + + int k = Integer.parseInt(sc.nextLine());//操作的次数 + String[] sLeft = sc.nextLine().split(" "); + int[] left = Arrays.stream(sLeft).mapToInt(Integer::parseInt).toArray(); + String[] sRight = sc.nextLine().split(" "); + int[] right = Arrays.stream(sRight).mapToInt(Integer::parseInt).toArray(); + + String sDeal = sc.nextLine(); + + char[] deal = sDeal.toCharArray();//操作手段 + + String[] sDealNum = sc.nextLine().split(" "); + + int[] dealNum = Arrays.stream(sDealNum).mapToInt(Integer::parseInt).toArray(); + new Question3().sovle(nums, left, right, deal, dealNum); + + } + + @Test + public void test1() { + int[] nums = {5, 4, 7, 4}; + int[] left = {1, 2, 3, 2}; + int[] right = {4, 3, 4, 2}; + char[] deal = {'=', '|', '&', '='}; + int[] dealNum = {8, 3, 6, 2}; + sovle1(nums, left, right, deal, dealNum); + } + + public void sovle(int[] nums, int[] left, int[] right, char[] deal, int[] dealNum) { + + //分别对数据进行操作 + for (int i = 0; i < left.length; i++) { + + int start = left[i] - 1; + int end = right[i] - 1; + + for (int j = start; j <= end; j++) { + if (deal[i] == '|') { + nums[j] |= dealNum[i]; + } else if (deal[i] == '&') { + nums[j] &= dealNum[i]; + } else if (deal[i] == '=') { + nums[j] = dealNum[i]; + } + } + } + for (int i = 0; i < nums.length; i++) { + System.out.print(nums[i] + " "); + } + + + } + + public void sovle1(int[] nums, int[] left, int[] right, char[] deal, int[] dealNum) { + + //分别对数据进行操作 + for (int i = 0; i < left.length; i++) { + + int start = left[i] - 1; + int end = right[i] - 1; + + if (deal[i] == '|') { + for (int j = start; j <= end; j++) { + nums[j] |= dealNum[i]; + } + } else if (deal[i] == '&') { + for (int j = start; j <= end; j++) { + nums[j] &= dealNum[i]; + } + } else if (deal[i] == '=') { + for (int j = start; j <= end; j++) { + nums[j] = dealNum[i]; + } + } + + } + for (int i = 0; i < nums.length; i++) { + System.out.print(nums[i] + " "); + } + + + } +} diff --git a/interview/Tencent/src/main/java/com/markilue/interview/ListNode.java b/interview/Tencent/src/main/java/com/markilue/interview/ListNode.java new file mode 100644 index 0000000..d496916 --- /dev/null +++ b/interview/Tencent/src/main/java/com/markilue/interview/ListNode.java @@ -0,0 +1,30 @@ +package com.markilue.interview; + +import java.util.List; + +/** + * @BelongsProject: Tencent + * @BelongsPackage: com.markilue.interview + * @Author: marklue + * @CreateTime: 2023/3/26 20:01 + * @Description: TODO + * @Version: 1.0 + */ +public class ListNode { + + int val; + ListNode next = null; + + public ListNode() { + } + + + public ListNode(int val) { + this.val = val; + } + + public ListNode(int val,ListNode next) { + this.val = val; + this.next=next; + } +} diff --git a/interview/Tencent/src/main/java/com/markilue/interview/Question1.java b/interview/Tencent/src/main/java/com/markilue/interview/Question1.java new file mode 100644 index 0000000..19c9559 --- /dev/null +++ b/interview/Tencent/src/main/java/com/markilue/interview/Question1.java @@ -0,0 +1,59 @@ +package com.markilue.interview; + +import java.util.ArrayList; +import java.util.List; + +/** + * @BelongsProject: Tencent + * @BelongsPackage: com.markilue.interview + * @Author: marklue + * @CreateTime: 2023/3/26 20:01 + * @Description: TODO + * @Version: 1.0 + */ +public class Question1 { + + /** + * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 + * + * @param head ListNode类 + * @return ListNode类 + */ + public ListNode reorderList(ListNode head) { + // write code here + if (head.next == null || head.next.next == null) return head; + + ListNode dummy = new ListNode(0, head); + ListNode fake = dummy; + ListNode cur = head.next; + ListNode temp; + + while (cur != null && cur.next != null && cur.next.next != null) { + temp = cur.next.next.next; + cur.next.next.next = dummy.next; + dummy.next = cur.next; + cur.next = temp; + + dummy = cur; + if (temp != null) { + cur = temp.next; + } + } + + if (cur != null && cur.next != null && cur.next.next == null) { + temp=cur.next; + temp.next=dummy.next; + cur.next=null; + dummy.next=temp; + } + return fake.next; + + + } + + public void swap(List list, int left, int right) { + int temp = list.get(left); + list.set(left, list.get(right)); + list.set(right, temp); + } +} diff --git a/interview/Tencent/src/main/java/com/markilue/interview/Question2.java b/interview/Tencent/src/main/java/com/markilue/interview/Question2.java new file mode 100644 index 0000000..c10ac79 --- /dev/null +++ b/interview/Tencent/src/main/java/com/markilue/interview/Question2.java @@ -0,0 +1,69 @@ +package com.markilue.interview; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Scanner; + +/** + * @BelongsProject: Tencent + * @BelongsPackage: com.markilue.interview + * @Author: marklue + * @CreateTime: 2023/3/26 20:23 + * @Description: TODO + * @Version: 1.0 + */ +public class Question2 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int k = Integer.parseInt(sc.nextLine()); + String[] s = new String[k]; + for (int i = 0; i < k; i++) { + s[i] = sc.nextLine(); + } + } + + @Test + public void test(){ + String[] s={"ab","ca","ccb"}; + sovle(s); + } + + public void sovle(String[] s) { + + backtracking(s,0,new boolean[24]); + System.out.println(result1); + + + } + + StringBuilder sb = new StringBuilder(); + List result = new ArrayList(); + int result1=0; + + public void backtracking(String[] s, int i, boolean[] used) { + + if (i == s.length) { + result1++; + result.add(new String(sb)); + return; + } + HashSet set = new HashSet<>(); + for (int j = 0; j < s[i].length(); j++) { + char c = s[i].charAt(j); + if (!set.contains(c)&&!used[c - 'a']) { + used[c - 'a'] = true; + set.add(c); + sb.append(c); + backtracking(s, i + 1, used); + sb.deleteCharAt(sb.length() - 1); + used[c-'a']=false; + } + } + + + } +} diff --git a/interview/Tencent/src/main/java/com/markilue/interview/Question3.java b/interview/Tencent/src/main/java/com/markilue/interview/Question3.java new file mode 100644 index 0000000..f26f317 --- /dev/null +++ b/interview/Tencent/src/main/java/com/markilue/interview/Question3.java @@ -0,0 +1,85 @@ +package com.markilue.interview; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Scanner; + +/** + * @BelongsProject: Tencent + * @BelongsPackage: com.markilue.interview + * @Author: marklue + * @CreateTime: 2023/3/26 20:51 + * @Description: TODO + * @Version: 1.0 + */ +public class Question3 { + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[] A = new int[n]; + int[] B = new int[n]; + + for (int i = 0; i < n; i++) { + A[i]=sc.nextInt(); + } + for (int i = 0; i < n; i++) { + B[i]=sc.nextInt(); + } + + new Question3().sovle(A,B); + + } + + @Test + public void test(){ + int[] A={1,10}; + int[] B={1,0}; + sovle(A,B); + } + + public void sovle(int[] A,int[] B){ + + ArrayList list0 = new ArrayList<>(); + ArrayList list1 = new ArrayList<>(); + ArrayList list2 = new ArrayList<>(); + + for (int i = 0; i < B.length; i++) { + if(B[i]==0){ + list0.add(i); + }else if(B[i]==1){ + list1.add(i); + }else { + list2.add(i); + } + } + Collections.sort(list0, (a,b) ->A[a]-A[b]); + Collections.sort(list1, (a,b) ->A[a]-A[b]); + Collections.sort(list2, (a,b) ->A[a]-A[b]); + int[] c = new int[A.length]; + int k=0; + + for (Integer i : list0) { + c[i]=++k; + } + + for (Integer i : list1) { + c[i]=++k; + } + + for (Integer i : list2) { + c[i]=++k; + } + + long result=0; + for (int i = 0; i < A.length; i++) { + result+=Math.abs(c[i]-A[i]); + } + System.out.println(result); + + } +} diff --git a/interview/Tencent/src/main/java/com/markilue/interview/Question4.java b/interview/Tencent/src/main/java/com/markilue/interview/Question4.java new file mode 100644 index 0000000..561613c --- /dev/null +++ b/interview/Tencent/src/main/java/com/markilue/interview/Question4.java @@ -0,0 +1,127 @@ +package com.markilue.interview; + +import org.junit.Test; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Scanner; + +/** + * @BelongsProject: Tencent + * @BelongsPackage: com.markilue.interview + * @Author: marklue + * @CreateTime: 2023/3/26 21:09 + * @Description: TODO + * @Version: 1.0 + */ +public class Question4 { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int[] nums = new int[n]; + for (int i = 0; i < n; i++) { + nums[i] = sc.nextInt(); + } + } + + @Test + public void test() { + int[] nums = {1, 2, 1}; + sovle3(nums); + } + + public void sovle(int[] nums) { + + Arrays.sort(nums); + backtracking(nums, 0, 1, 0, 0); + System.out.println(result); + + } + + @Test + public void test3() { + System.out.println(0 ^ 2); + } + + + List cur = new ArrayList<>(); + List> result = new ArrayList<>(); + + public void backtracking(int[] nums, int start, int cheng, int yi, int level) { + if (level != 0 && cheng == yi) { + result.add(new ArrayList<>(cur)); + } + + for (int i = start; i < nums.length; i++) { +// if (i != start && nums[i] == nums[i - 1]) { +// continue; +// } + + cur.add(nums[i]); + backtracking(nums, i + 1, cheng * nums[i], yi ^ nums[i], level + 1); + cur.remove(cur.size() - 1); + + + } + + } + + + public void solve1(int[] nums) { + + int result = 0; + for (int i = 0; i < nums.length; i++) { + int cheng = 1; + int yihou = 0; + for (int j = i; j < nums.length; j++) { + cheng *= nums[j]; + yihou ^= nums[j]; + if (cheng == yihou) result++; + } + } + System.out.println(result); + } + + + //统计每个词出现的个数 + public void sovle3(int[] nums) { + + int max = 0; + int min = Integer.MAX_VALUE; + + //统计每个词出现的次数 + for (int i = 0; i < nums.length; i++) { + if (max < nums[i]) max = nums[i]; + if (min > nums[i]) min = nums[i]; + } + + int[] count = new int[max - min + 1]; + + int result = 0; + for (int i = 0; i < nums.length; i++) { + count[nums[i] - min]++; + result++;//统计单个的值 + } + + ArrayList count1 = new ArrayList<>(); + int num = 0; + for (int i = 0; i < count.length; i++) { + //统计个数超过2的值 + if (count[i] != 0) num++; + if (count[i] >= 2) { + int temp = count[i] / 2; + count1.add(temp); + } + } + int total = 1; + for (int i = 0; i < count1.size(); i++) { + total *= count1.get(i); + } + result += total * (num - 1); + System.out.println(result); + + } +} diff --git a/java_web/Tecent/pom.xml b/java_web/Tecent/pom.xml new file mode 100644 index 0000000..04e13d4 --- /dev/null +++ b/java_web/Tecent/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + com.makrilue.interview + Tecent + 1.0-SNAPSHOT + + + + junit + junit + 4.13.2 + test + + + junit + junit + 4.13.2 + compile + + + + + 8 + 8 + + + \ No newline at end of file diff --git a/java_web/Tecent/src/main/java/com/markilue/interview/Question3.java b/java_web/Tecent/src/main/java/com/markilue/interview/Question3.java new file mode 100644 index 0000000..370376f --- /dev/null +++ b/java_web/Tecent/src/main/java/com/markilue/interview/Question3.java @@ -0,0 +1,57 @@ +package com.markilue.interview; + +import org.junit.Test; +import org.junit.runner.notification.RunListener; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; + +public class Question3 { + + @Test + public void test() { + String s = "nowcoder"; + String[] dic = {"now", "coder", "no", "wcoder"}; + System.out.println(Arrays.toString(wordDiv(s, dic))); + } + + /** + * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 + * + * @param s string字符串 + * @param dic string字符串一维数组 + * @return string字符串一维数组 + */ + public String[] wordDiv(String s, String[] dic) { + // write code here + List result = new ArrayList<>(); + if (s == null || s.length() == 0 || dic.length == 0) { + return result.toArray(new String[0]); + } + List wordDic = Arrays.asList(dic); + HashSet set = new HashSet<>(wordDic); + StringBuilder sb = new StringBuilder(); + backtracking(s, set, 0, sb, result); + return result.toArray(new String[0]); + } + + private void backtracking(String s, HashSet set, int start, StringBuilder sb, List result) { + if (start == s.length()) { + result.add(sb.toString().trim()); + return; + } + + for (int i = start; i < s.length(); i++) { + String word = s.substring(start, i + 1); + if (set.contains(word)) { + sb.append(word).append(" "); + backtracking(s, set, i + 1, sb, result); + sb.delete(sb.length() - word.length() - 1, sb.length()); + } + } + } + + +} diff --git a/java_web/Tecent/src/main/java/com/markilue/interview/Question4.java b/java_web/Tecent/src/main/java/com/markilue/interview/Question4.java new file mode 100644 index 0000000..5df695f --- /dev/null +++ b/java_web/Tecent/src/main/java/com/markilue/interview/Question4.java @@ -0,0 +1,6 @@ +package com.markilue.interview; + +public class Question4 { + + +}