CCF试题 201312-2 ISBN号码 JAVA实现

CCF试题 201312-2 ISBN号码 JAVA实现_第1张图片

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String sa = sc.next();
        String[] sx = sa.split("-");

        int a, b, c, d;
        a = Integer.parseInt(sx[0]);
        b = Integer.parseInt(sx[1]);
        c = Integer.parseInt(sx[2]);
        if (sx[3].equals("X")) {
            d = 10;
        } else {
            d = Integer.parseInt(sx[3]);
        }

        int index;
        index = (a + (b / 100) * 2 + ((b / 10) % 10) * 3 + (b % 10) * 4 + ((c / 10000) * 5) + ((c / 1000) % 10) * 6
                + ((c / 100) % 10) * 7 + ((c / 10) % 10) * 8 + (c % 10) * 9) % 11;
        if (d == index) {
            System.out.println("Right");
        } else if (index < 10) {
            System.out.println(sx[0] + "-" + sx[1] + "-" + sx[2] + "-" + index);
        } else {
            System.out.println(sx[0] + "-" + sx[1] + "-" + sx[2] + "-" + "X");
        }

    }

}

你可能感兴趣的:(CCF试题 201312-2 ISBN号码 JAVA实现)