zoukankan      html  css  js  c++  java
  • 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);
                    }
                }
            }
        }
    }
    
  • 相关阅读:
    和园友们聊聊天
    php编写验证码
    面试题复习记录(二)
    面试题复习记录(一)
    正则表达式学习小记
    javascript学习小记(一)
    大四
    Java小应用程序
    明白这十个故事-->你也就参悟了人生
    Hibernate懒加载深入分析
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076690.html
Copyright © 2011-2022 走看看