Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
用Java语言写,所有的数据都试过符合,但提交还是显示错,太神了!不信你试试。用Java语言写,所有的数据都试过了,控制台输出的结果都符合,试了n遍,但提交出还是显示错,太神了!有人看得出什么问题吗?不信你试试。 import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); int[] stack=new int[1024]; String output=""; try{ int t=Integer.parseInt(input.readLine()); for(int i=0;i<t;i++){ int n=Integer.parseInt(input.readLine().trim()); String pstr=input.readLine(); //用负数表示左括号个数,正数表示w int index=0; stack[index]='1'-pstr.charAt(0); index++;stack[index]=1; output+="1"; for(int j=1;j<n;j++){ int left=pstr.charAt(j+j-2)-pstr.charAt(j+j); if(left<-1){ index++;stack[index]=left+1; index++;stack[index]=1; output+=" "+1; } else if(left==-1){ stack[index]++; output+=" "+1; } else {//left==0 stack[index]++; output+=" "+stack[index]; if(stack[index-1]==-1&&index-2>-1){ index=index-2;stack[index]=stack[index]+stack[index+2]; } else{ stack[index-1]++; } } } output+="\n"; } } catch(Exception e){ } System.out.print(output); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator