[BaekJoon] 2420번 - 사파리월드 [Java][C++]
[BaekJoon] 2420번 - 사파리월드 [Java][C++]
1. 문제 풀이
두 정수 $N$, $M$ 에 대해 두 수의 차의 절댓값을 출력하는 문제로 오버플로우만 주의하면 된다.
2. 코드
1. 풀이 [Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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));
StringTokenizer st = new StringTokenizer(br.readLine());
long N = Long.parseLong(st.nextToken());
long M = Long.parseLong(st.nextToken());
System.out.println(Math.abs(N - M));
}
}
2. 풀이 [C++]
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n, m;
cin >> n >> m;
cout << abs(n - m);
}
This post is licensed under CC BY 4.0 by the author.