[BaekJoon] 10093번 - 숫자 [Java][C++]
[BaekJoon] 10093번 - 숫자 [Java][C++]
1. 문제 풀이
두 정수 사이의 모든 정수를 출력하는 문제로 $A$ 가 $B$ 보다 클 수 있음에만 주의하면 된다.
2. 코드
1. 풀이 [Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
long A = Long.parseLong(st.nextToken());
long B = Long.parseLong(st.nextToken());
if (A > B) {
long tmp = A;
A = B;
B = tmp;
}
sb.append(Math.max(B - A - 1, 0)).append("\n");
for (long i = A + 1; i < B; i++) {
sb.append(i).append(" ");
}
System.out.println(sb);
}
}
2. 풀이 [C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long a, b;
cin >> a >> b;
if (a > b) swap(a, b);
cout << max(b - a - 1, 0LL) << '\n';
for (long long i = a + 1; i < b; i++) {
cout << i << ' ';
}
}
This post is licensed under CC BY 4.0 by the author.