[BaekJoon] 2475번 - 검증수 [Java][C++]
[BaekJoon] 2475번 - 검증수 [Java][C++]
1. 문제 풀이
각 수의 제곱을 합한 후 모듈러 연산으로 10으로 나눠주기만 하면 된다.
2. 코드
1. 풀이 [Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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());
int sum = 0;
for (int i = 0; i < 5; i++) {
int n = Integer.parseInt(st.nextToken());
sum += n * n;
}
System.out.println(sum % 10);
}
}
2. 풀이 [C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int sum = 0;
for (int i = 0; i < 5; i++) {
int n;
cin >> n;
sum += n * n;
}
cout << sum % 10;
}
This post is licensed under CC BY 4.0 by the author.