백준 - 숫자 (브론즈 2)
2024. 2. 28. 18:43ㆍ코딩테스트 정리(자바)
728x90
A가 항상 B보다 크다고 생각했다
그러나 조건을 따졌어야 함.
B가 더 클 수도 있고
둘이 같을 수도 있음.
이런 조건들을 잘 따져보자 !!
import java.io.*;
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
String[] arr=br.readLine().split(" ");
long start=0;
long end=0;
long A=Long.parseLong(arr[0]);
long B=Long.parseLong(arr[1]);
if(A>B) {
start = B;
end = A;
}
else if(B>A){
start=A;
end=B;
}
else{
System.out.print(0);
return;
}
System.out.println(end-start-1);
for(long i=start+1;i<end;i++){
System.out.print(i+" ");
}
}
}728x90
'코딩테스트 정리(자바)' 카테고리의 다른 글
| 백준 - 방 배정 (브론즈 2) (0) | 2024.03.02 |
|---|---|
| 백준 - 두수의 합 (실버 3) (5) | 2024.03.01 |
| 백준 - 일곱 난쟁이 (브론즈 1) (0) | 2024.02.28 |
| 백준 - 입력 받기 (0) | 2024.02.27 |
| 프로그래머스 - 최소직사각형 (Level 1) (0) | 2024.02.27 |