Merge remote-tracking branch 'origin/master'

This commit is contained in:
markilue 2023-03-28 22:10:31 +08:00
commit f325bf8015
22 changed files with 1370 additions and 0 deletions

Binary file not shown.

82
GE_migate/pom.xml Normal file
View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cqu.ge</groupId>
<artifactId>GE_migate</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.cqu</groupId>
<artifactId>ge</artifactId>
<version>1.0.0</version>
</dependency>
<!--utgard -->
<!-- <dependency>-->
<!-- <groupId>org.openscada.external</groupId>-->
<!-- <artifactId>org.openscada.external.jcifs</artifactId>-->
<!-- <version>1.2.25</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.bouncycastle</groupId>-->
<!-- <artifactId>bcprov-jdk15on</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!--&lt;!&ndash; <dependency>&ndash;&gt;-->
<!--&lt;!&ndash; <groupId>org.openscada.jinterop</groupId>&ndash;&gt;-->
<!--&lt;!&ndash; <artifactId>org.openscada.jinterop.core</artifactId>&ndash;&gt;-->
<!--&lt;!&ndash; <version>2.1.8</version>&ndash;&gt;-->
<!--&lt;!&ndash; </dependency>&ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.openscada.jinterop</groupId>-->
<!-- <artifactId>org.openscada.jinterop.deps</artifactId>-->
<!-- <version>1.5.0</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.bouncycastle</groupId>-->
<!-- <artifactId>bcprov-jdk15on</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.openscada.utgard</groupId>-->
<!-- <artifactId>org.openscada.opc.dcom</artifactId>-->
<!-- <version>1.5.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.openscada.utgard</groupId>-->
<!-- <artifactId>org.openscada.opc.lib</artifactId>-->
<!-- <version>1.5.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.bouncycastle</groupId>-->
<!-- <artifactId>bcprov-jdk15on</artifactId>-->
<!-- <version>1.61</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>ch.qos.logback</groupId>-->
<!-- <artifactId>logback-core</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>ch.qos.logback</groupId>-->
<!-- <artifactId>logback-classic</artifactId>-->
<!-- </dependency>-->
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@ -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<String,String> 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<String,String> map = new HashMap<String, String>();
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<parameters.length;i++){
ps.setString(i+1, parameters[i]);
}
}
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}finally{
OracleODBC.close(conn, ps, rs);
}
}
//查询方法
public static ResultSet executeQuery(String sql,String []parameters){
try {
conn = DriverManager.getConnection(odbc_url, username, password);
ps = conn.prepareStatement(sql);
if(parameters !=null){
for(int i=0;i<parameters.length;i++){
ps.setString(i+1, parameters[i]);
}
}
//执行查询
rs = ps.executeQuery();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}finally{
//关闭资源
//SQLHelper.close(conn, ps, rs);
}
return rs;
}
//关闭资源
public static void close(Connection conn,Statement stmt,ResultSet rs){
if(rs!=null){
try {
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
rs = null;
}
if(stmt!=null){
try {
stmt.close();
} catch (Exception e) {
e.printStackTrace();
}
stmt = null;
}
if(conn!=null){
try {
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
conn=null;
}
}
public static Connection getConn() {
return conn;
}
public static PreparedStatement getPs() {
return ps;
}
}

View File

@ -0,0 +1,55 @@
package com.cqu.ge;
import com.sun.security.ntlm.Server;
import org.junit.Test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class TestData {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String ds="jdbc:odbc:Provider=IhOLEDB.iHistorian.1;Persist Security Info=True;Mode=Read;Data Source=192.168.9.8";
// String ds="Provider=IhOLEDB.iHistorian.1;Persist Security Info=True;Mode=Read;Data Source=192.168.9.8";
String user="administrator";
String password="TES@ihistorian2018";
Class.forName(driver);
Connection connection = DriverManager.getConnection(ds, user, password);
//3.定义sql
String sql = "select * from ihTags where tagname= [HN.DF.DF11.DF11_TC1].AIO.AN_Air_Supply_Pressure ";
//4.获取执行sql对象statement
Statement statement = connection.createStatement();
//5.执行sql
int count = statement.executeUpdate(sql); //返回受影响的行数
//6.处理结果
System.out.println(count);
//7.释放资源
statement.close();
connection.close();
}
@Test
public void test(){
}
}

View File

@ -0,0 +1,42 @@
package com.cqu.ge;
import java.sql.*;
public class test1 {
public static void main(String[] args) {
try {
Class.forName("org.objectweb.rmijdbc.Driver").newInstance();
String strurl = "jdbc:rmi://111.11.1.1/jdbc:odbc:sundy4";
java.sql.Connection c = DriverManager.getConnection(strurl, "", "199302");
java.sql.Statement st = c.createStatement();
java.sql.ResultSet rs = st.executeQuery("select * from Users");
java.sql.ResultSetMetaData md = rs.getMetaData();
while(rs.next()) {
System.out.println();
for(int i=1; i<= md.getColumnCount(); i++) {
System.out.print(rs.getString(i) + " | ");
}
}
rs.close();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,88 @@
package com.markilue.leecode.interview.meituan;
import org.junit.Test;
import java.util.Scanner;
/**
* @BelongsProject: Leecode
* @BelongsPackage: com.markilue.leecode.interview.meituan
* @Author: marklue
* @CreateTime: 2023/3/25 19:08
* @Description: TODO
* @Version: 1.0
*/
public class Question2 {
@Test
public void test() {
int value = 7;
int[] nums = {3, 1, 2, 7, 10, 2, 4};
sovle1(nums);
}
public void sovle(int[] nums) {
int n = nums.length;
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] + 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]);
}
}

View File

@ -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];
}
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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()

View File

@ -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<Character, Character> map = new HashMap<Character, Character>() {{
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));
}
}

View File

@ -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);
}
}
}

View File

@ -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] + " ");
}
}
}

View File

@ -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;
}
}

View File

@ -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<Integer> list, int left, int right) {
int temp = list.get(left);
list.set(left, list.get(right));
list.set(right, temp);
}
}

View File

@ -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<String> result = new ArrayList<String>();
int result1=0;
public void backtracking(String[] s, int i, boolean[] used) {
if (i == s.length) {
result1++;
result.add(new String(sb));
return;
}
HashSet<Character> 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;
}
}
}
}

View File

@ -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<Integer> list0 = new ArrayList<>();
ArrayList<Integer> list1 = new ArrayList<>();
ArrayList<Integer> 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);
}
}

View File

@ -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<Integer> cur = new ArrayList<>();
List<List<Integer>> 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<Integer> 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);
}
}

31
java_web/Tecent/pom.xml Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.makrilue.interview</groupId>
<artifactId>Tecent</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@ -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<String> result = new ArrayList<>();
if (s == null || s.length() == 0 || dic.length == 0) {
return result.toArray(new String[0]);
}
List<String> wordDic = Arrays.asList(dic);
HashSet<String> 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<String> set, int start, StringBuilder sb, List<String> 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());
}
}
}
}

View File

@ -0,0 +1,6 @@
package com.markilue.interview;
public class Question4 {
}