Java实现 洛谷 P1055 ISBN号码

在这里插入图片描述

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

public class Main{
    public static void main(String args[]) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String ISBN = reader.readLine();
        String[] temp = ISBN.split("-");
        String str = "";
        int check = 0;
        int x = 0;
        String front = ISBN.substring(0, ISBN.length() - 1);

        for (int i = 0; i < temp.length; i++){
            str += temp[i];
        }

        for (int i = 0; i < str.length()-1; i++){
            x = Integer.parseInt(String.valueOf(str.charAt(i)));
            check += (i+1)*x;
        }

        if (str.charAt(str.length()-1)=='X'){
            if (check % 11 == 10) {
                System.out.println("Right");
            } else {
                System.out.println(front + check % 11);
            }
        } else {
            if (check%11 == Integer.parseInt(String.valueOf(str.charAt(str.length()-1)))){
                System.out.println("Right");
            } else {
                if (check % 11 == 10) {
                    System.out.println(front + "X");
                } else {
                    System.out.println(front + check % 11);
                }
            }
        }
    }
}
posted @ 2019-07-30 19:45  南墙1  阅读(59)  评论(0编辑  收藏  举报