import java.util.Scanner;
import java.util.Stack;
public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int k=sc.nextInt(); Stack<Integer> tack=new Stack<Integer>();
int count=1;
for(int i=0;i<k;i++) { int num=sc.nextInt(); boolean cheak=false; if(i!=0) { if(num<count){ cheak=true; } } if(cheak==false) { for(int j=count;j<=k;j++) { if(j==num) { tack.push(j); System.out.println("+"); count=j+1; break; } else { tack.push(j); System.out.println("+"); } } tack.pop(); System.out.println("-"); } else { if(num!=tack.get(tack.size()-1)) { System.out.println("NO"); break; } tack.pop(); System.out.println("-"); } } }}
최대한 줄인건데도 출력초과가 떠요...
이방법으로는 안되는건가요?? 아 그리고 출력초과가 정확히 뭔가요?
카테고리를 질문으로 바꾸면 문제 번호와 소스코드를 적는 칸이 나옵니다.
출력초과 설명은 https://www.acmicpc.net/help 에 있습니다.
댓글을 작성하려면 로그인해야 합니다.
tjgy9023 6년 전
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int k=sc.nextInt();
Stack<Integer> tack=new Stack<Integer>();
int count=1;
for(int i=0;i<k;i++) {
int num=sc.nextInt();
boolean cheak=false;
if(i!=0) {
if(num<count){
cheak=true;
}
}
if(cheak==false) {
for(int j=count;j<=k;j++) {
if(j==num) {
tack.push(j);
System.out.println("+");
count=j+1;
break;
}
else
{
tack.push(j);
System.out.println("+");
}
}
tack.pop();
System.out.println("-");
}
else {
if(num!=tack.get(tack.size()-1)) {
System.out.println("NO");
break;
}
tack.pop();
System.out.println("-");
}
}
}
}
최대한 줄인건데도 출력초과가 떠요...
이방법으로는 안되는건가요?? 아 그리고 출력초과가 정확히 뭔가요?