📄 delimitermatch.java
字号:
import java.io.*;
import java.util.*;
public class DelimiterMatch {
Stack stack = new Stack();
public void Matching()throws IOException{
String s = " ";char temp=' ',next=' ';
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
s = br.readLine();
}catch(IOException e){
}
for(int i=0;i<=s.length();i++){
if(i<s.length()){
temp = s.charAt(i);
if (temp == '(' || temp == '[') {
stack.push(i);
stack.push(temp);
}
if (temp == ')' && stack.isEmpty())
System.out.println("不匹配信息为: ) in colum " + i +
" is not matching");
if (temp == ']' && stack.isEmpty())
System.out.println("不匹配信息为: ] in colum " + i +
" is not matching");
if (temp == ')' && !stack.isEmpty()) {
next = (Character) stack.pop();
int m = (Integer) stack.pop();
if (next == '(')
continue;
else
System.out.println("不匹配信息为: " + next + " in colum " + m +
" is not matching with ) in colum " +
i);
}
if (temp == ']' && !stack.isEmpty()) {
next = (Character) stack.pop();
int m = (Integer) stack.pop();
if (next == '[')
continue;
else
System.out.println("不匹配信息为: " + next + " in colum " + m +
" is not matching with ] in colum " +i);
}
}
if(i==s.length()&&!stack.isEmpty())
for (; !stack.isEmpty(); ) {
next = (Character) stack.pop();
int m = (Integer) stack.pop();
System.out.println("不匹配信息为: " + next + " in colum " + m +
" is not matching ");
}
}
}
public static void main(String[] args)throws IOException {
DelimiterMatch delimitermatch = new DelimiterMatch();
delimitermatch.Matching();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -