?? delimitermatch.java~18~
字號:
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++){
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()-1&&temp!=')'&&temp!=']'&&!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 + -