반응형
https://www.acmicpc.net/problem/6810
6810번: ISBN
The International Standard Book Number (ISBN) is a 13-digit code for identifying books. These numbers have a special property for detecting whether the number was written correctly. The 1-3-sum of a 13-digit number is calculated by multiplying the digits a
www.acmicpc.net
코드
#include <iostream>
using namespace std;
int main() {
int a[3], sum = 91;
for (int i = 0; i < 3; i++) {
cin >> a[i];
if (i == 1) {
a[i] = 3 * a[i];
}
sum = sum + a[i];
}
cout << "The 1-3-sum is " << sum;
return 0;
}
풀이
국제 표준 도서 번호 ISBN의 형식을 맞추기 위해 입력한 값을 활용해 정해진 출력이 나오게 하는 문제이다.
for 문을 사용해 배열에 3개의 정수를 입력받고, 첫 번째 숫자와 세 번째 숫자는 그대로 더하고 두 번째 숫자에는 3을 곱한 뒤 총합을 sum에 저장하여 출력한다.
첫 10자리는 9780921418로 고정되어 있기에 ISBN식에 맞추어 계산한다.
반응형
'문제 해결 > BaekJoon' 카테고리의 다른 글
[백준] [C++] 8370번 Plane (0) | 2022.11.14 |
---|---|
[백준] [C++] 7891번 Can you add this? (0) | 2022.11.14 |
[백준] [C++] 6778번 Which Alien? (0) | 2022.11.13 |
[백준] [C++] 6749번 Next in line (0) | 2022.11.13 |
[백준] [C++] 5522번 카드 게임 (0) | 2022.11.13 |