-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc738f2
commit 185ea6f
Showing
3 changed files
with
302 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import java.util.*; | ||
import java.lang.*; | ||
|
||
class FormatPath { | ||
Vector<String> path; | ||
String input; | ||
String output; | ||
|
||
public FormatPath(String s) { | ||
this.input = s.replace('\\','/'); | ||
this.path = new Vector<String>(); | ||
this.output = ""; | ||
try { | ||
this.deal(); | ||
} catch (Exception e) { | ||
this.output = "Value Error"; | ||
} | ||
} | ||
|
||
private void deal() throws Exception { | ||
if (this.input.length() == 0) { | ||
throw new Exception("Empty."); | ||
} | ||
|
||
int cursor; | ||
int start; | ||
int end; | ||
start = 0; | ||
end = 0; | ||
if (this.input.length() > 1) { | ||
if (this.input.charAt(0) == '/') { | ||
this.output = "/"; | ||
} | ||
for (cursor = 1; cursor < this.input.length(); cursor++) { | ||
switch (this.input.charAt(cursor - 1)){ | ||
case '/': | ||
start = cursor; | ||
break; | ||
case '.': | ||
if (this.input.charAt(cursor) == '.') { | ||
if (this.path.isEmpty()) { | ||
throw new Exception("Wrong Expression."); | ||
} | ||
this.path.remove(this.path.size() - 1); | ||
} | ||
break; | ||
default: | ||
if (this.input.charAt(cursor) == '/') { | ||
end = cursor; | ||
this.path.add(this.input.substring(start, end)); | ||
} | ||
break; | ||
} | ||
|
||
} | ||
if (start < this.input.length() && this.input.charAt(this.input.length() - 1) != '/') { | ||
if (!this.input.substring(start).equals("/") && !this.input.substring(start).equals(".")) { | ||
this.path.add(this.input.substring(start)); | ||
} | ||
if (this.input.substring(start).equals("..")) { | ||
if (this.path.isEmpty()) { | ||
throw new Exception("Wrong Expression."); | ||
} | ||
this.path.remove(this.path.size() - 1); | ||
} | ||
} | ||
} else { | ||
if (!this.input.equals(".")) { | ||
this.path.add(this.input); | ||
} | ||
} | ||
|
||
for (cursor = 0; cursor < this.path.size(); cursor++) { | ||
this.output += this.path.get(cursor) + "/"; | ||
} | ||
|
||
if (this.path.size() != 0) { | ||
this.output = this.output.substring(0, this.output.length() - 1); | ||
} | ||
|
||
} | ||
|
||
public String getOutput() { | ||
return this.output; | ||
} | ||
} | ||
|
||
public class Main { | ||
public static void main(String []args) { | ||
System.out.println("Java 2020."); | ||
Scanner scanner = new Scanner(System.in); | ||
while (scanner.hasNext()) { | ||
String string = scanner.nextLine(); | ||
FormatPath path = new FormatPath(string); | ||
System.out.println(path.getOutput()); | ||
} | ||
} | ||
} | ||
|
||
// Powered by Intellij IDEA Community Edition 2020.1. | ||
|
||
//./jisuanke\\./suantou/../bin/ | ||
//.. | ||
///\./\.\/.\/ | ||
|
||
//测评信息 | ||
// ================================================ | ||
// 测评用例 1:答案错误 [165.000 毫秒,10896 KB] | ||
// 用例输入: | ||
// a\\B | ||
// \\\\A\\\\B | ||
// \\\\A\\\\B | ||
// | ||
// 用例正确输出: | ||
// a/B | ||
// /A/b | ||
// /A/B | ||
// | ||
// 你的输出: | ||
// a | ||
// /A | ||
// /A | ||
// --------------------------- | ||
// 测评用例 2:答案错误 [143.000 毫秒,10900 KB] | ||
// --------------------------- | ||
// 测评用例 3:答案错误 [129.000 毫秒,10908 KB] | ||
// --------------------------- | ||
// 测评用例 4:答案错误 [152.000 毫秒,10932 KB] | ||
// --------------------------- | ||
// 测评用例 5:答案错误 [159.000 毫秒,10880 KB] | ||
// --------------------------- | ||
// 测评用例 6:答案错误 [155.000 毫秒,10908 KB] | ||
// | ||
// 结果 | ||
// ================================================ | ||
// 共 6 组测评用例,通过 0 组。 | ||
// | ||
// / | ||
// . | ||
// /. | ||
// 1/.. | ||
// 1/../ | ||
// /1/.. | ||
// /1/../ | ||
// | ||
// 用例正确输出: | ||
// / | ||
// | ||
// / | ||
// | ||
// | ||
// / | ||
// / | ||
// | ||
// 你的输出: | ||
// / | ||
// . | ||
// / | ||
// | ||
// | ||
// / | ||
// / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import java.sql.*; | ||
|
||
public class SQL { | ||
public static void main(String []args) { | ||
int status = 1; | ||
try { | ||
if (status == 0) { | ||
throw new Exception(""); | ||
} | ||
String url = "jdbc:mysql://localhost:3306/jpetstore?autoReconnect=true"; | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// String mysql = "jdbc:mysql://localhost:3306/mail?user=root&password=root"; | ||
String mysql = "jdbc:mysql://localhost:3306/mail?serverTimezone=Asia/Shanghai"; | ||
String user = "root"; | ||
String passwd = "root"; | ||
try { | ||
Class.forName("com.mysql.cj.jdbc.Driver"); | ||
System.out.println("OK Load Finished."); | ||
Connection connection = DriverManager.getConnection(mysql,user,passwd); | ||
Statement statement = connection.createStatement(); | ||
String sql = "select * from goods"; | ||
ResultSet resultSet = statement.executeQuery(sql); | ||
while (resultSet.next()) { | ||
System.out.println(resultSet.getString("Goods_ID")); | ||
System.out.println(resultSet.getString("Goods_Type")); | ||
} | ||
statement.execute("insert into purchaser values(0,'Tom');"); | ||
// statement.execute("update purchaser set purchaser_name = 'Tommy' where purchaser_name = 'Tom';"); | ||
resultSet.close(); | ||
statement.close(); | ||
connection.close(); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import java.net.InetAddress; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import java.net.*; | ||
import java.io.*; | ||
import java.util.Scanner; | ||
|
||
public class Web { | ||
public static void main(String []args){ | ||
int no1 = 0; | ||
try { | ||
if (no1 == 0) throw new Exception(""); | ||
URL web = new URL("https://www.nankai.edu.cn"); | ||
System.out.println(web.getProtocol()); | ||
System.out.println(web.getHost()); | ||
System.out.println(web.getPort()); | ||
System.out.println(web.getFile()); | ||
BufferedReader in = new BufferedReader(new InputStreamReader(web.openStream())); | ||
String inputLine; | ||
//while ((inputLine = in.readLine()) != null) System.out.println(inputLine); | ||
in.close(); | ||
URLConnection urlConnection = web.openConnection(); | ||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); | ||
while ((inputLine = bufferedReader.readLine()) != null) { | ||
// System.out.println(inputLine); | ||
} | ||
bufferedReader.close(); | ||
} | ||
catch (Exception e) { | ||
// This is try to read web file lines. | ||
// Two methods are the same result. | ||
} | ||
try { | ||
if (no1 == 0) throw new Exception(""); | ||
InetAddress inetAddress = InetAddress.getLocalHost(); | ||
System.out.println(inetAddress); | ||
byte[] address = inetAddress.getAddress(); | ||
for (int i = 0; i < address.length ; i++) { | ||
System.out.println(address[i]); | ||
} | ||
System.out.println(inetAddress.getHostName()); | ||
System.out.println(inetAddress.getHostAddress()); | ||
} | ||
catch (Exception e) { | ||
|
||
} | ||
try { | ||
URL url = new URL("https://www.baidu.com/"); | ||
System.out.println(url); | ||
URL baseUrl = new URL(url,"file.html"); | ||
System.out.println(baseUrl); | ||
|
||
URL socketUrl = new URL("https://101.200.100.121:8080"); | ||
System.out.println(socketUrl); | ||
System.out.println(socketUrl.getProtocol()); | ||
System.out.println(socketUrl.getHost()); | ||
System.out.println(socketUrl.getPort()); | ||
System.out.println(socketUrl.getFile()); | ||
System.out.println(socketUrl.getRef()); | ||
} | ||
catch (MalformedURLException e) { | ||
|
||
} | ||
try { | ||
System.out.println("First"); | ||
// Socket socket = new Socket("101.200.155.187",8080); | ||
|
||
System.out.println("Local Host"); | ||
ServerSocket serverSocket = new ServerSocket(8080); | ||
System.out.println(serverSocket); | ||
System.out.println(serverSocket.getLocalSocketAddress()); | ||
System.out.println(serverSocket.getLocalPort()); | ||
serverSocket.close(); | ||
} | ||
catch (Exception e) { | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
|
||
class TestUrl { | ||
public static void main(String[] args) throws Exception { | ||
URL web = new | ||
URL("http://www.nankai.edu.cn"); | ||
System.out.println(web.getProtocol()); | ||
System.out.println(web.getHost()); | ||
System.out.println(web.getPort()); | ||
System.out.println(web.getFile()); | ||
BufferedReader in = new BufferedReader( | ||
new InputStreamReader(web.openStream())); | ||
String inputLine; | ||
while ((inputLine = in.readLine()) != null) | ||
System.out.println(inputLine); | ||
in.close(); | ||
} | ||
} |