Java/Java 알고리즘

백준 6810번 ISBN JAVA 구현해보기

kimc 2022. 1. 29. 12:15

```

백준 6810번 ISBN JAVA 구현해보기

```

이번 글을 통해 배워갈 내용

  1.  백준 6810번 풀이

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

 

 

백준 6810번 ISBN은

난이도 브론즈 등급의 문제로서

 

앞번호 9780921418948 이 주어지고 뒷 세 자리를 입력받을 때

 

각 자릿수를 1 3 순으로 곱해줘서 더해준 다음 출력하면 되는 문제입니다.

 


30분 정도 위에 링크를 방문하셔서 풀어보시고

안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.


 

숫자를 입력받고

13을 각 자릿수에 번갈아서 곱해준 다음

더해주었습니다.

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    private static String ISBN = "9780921418";
    private static int mod13 = 3;

    public static void main(String[] args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int sum = 0;
        for (String eachDigit : ISBN.split("")) {
            sum += Integer.parseInt(eachDigit) * getMod123();
        }

        for (int i = 0; i < 3; i++) {
            sum += Integer.parseInt(br.readLine()) * getMod123();
        }

        System.out.println("The 1-3-sum is " + sum);
    }

    private static int getMod123() {
        if (mod13 == 1) {
            mod13 = 3;
        } else {
            mod13 = 1;
        }
        return mod13;
    }
}

 

 

읽어주셔서 감사합니다

 

무엇인가 얻어가셨기를 바라며

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

728x90