import java.util.Scanner; public class b574 { public static void main(String[] args){ Scanner kin = new Scanner(System.in); while(kin.hasNext()){ int k = kin.nextInt(); int max=0,p=0; StringBuilder sb = new StringBuilder(); for(int i=1;i<=k;i++){ int x = kin.nextInt(); int c = kin.nextInt(); if(c%2==1){ sb.append(x+" "); p++; if(p>max) max=p; } else{ String d = x+" "; sb.delete(sb.indexOf(d),sb.indexOf(d)+d.length()); p--; } } System.out.println(max); } } }
通過檢測
通過檢測
通過檢測
您的程式被監控系統中斷,可能是程式無法正常結束所導致。 Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.AbstractStringBuilder.delete(AbstractStringBuilder.java:756) at java.lang.StringBuilder.delete(StringBuilder.java:244) at b574.main(b574.java:19)
您的程式被監控系統中斷,可能是程式無法正常結束所導致。 Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.AbstractStringBuilder.delete(AbstractStringBuilder.java:756) at java.lang.StringBuilder.delete(StringBuilder.java:244) at b574.main(b574.java:19)
為何第4、5筆測資會RE?