※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 9907번 문제인 ID이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/9907
9907번: ID
The National Identity Card number of the city state of Eropagnis, NICE, consists of seven digits and a letter appended behind. This letter is calculated from the digits using the Modulo Eleven method. The steps involved in the computation are as follows:
www.acmicpc.net
지문에 주어진 대로 주어진 정수를 0~10의 정수로 바꾼 뒤 대응되는 문자를 출력하는 문제이다. 주어진 계산 과정을 잘 구현해 문제를 해결하자.
아래의 ans와 같은 배열을 이용하면 구현을 더욱 편하게 할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long long ll;
int N, val;
char ans[11] = { 'J', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'Z' };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
val += (N % 10) * 2;
N /= 10;
val += (N % 10) * 3;
N /= 10;
val += (N % 10) * 4;
N /= 10;
val += (N % 10) * 5;
N /= 10;
val += (N % 10) * 6;
N /= 10;
val += (N % 10) * 7;
N /= 10;
val += N * 2;
val %= 11;
cout << ans[val];
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 26009 // C++] 험난한 등굣길 (0) | 2022.12.26 |
---|---|
[BOJ 26416 // C++] New Password (0) | 2022.12.26 |
[BOJ 26743 // C++] Oczko (0) | 2022.12.25 |
[BOJ 26766 // C++] Serca (0) | 2022.12.25 |
[BOJ 26742 // C++] Skarpetki (0) | 2022.12.25 |