题解 | #[NOIP2008]ISBN号码#

[NOIP2008]ISBN号码

https://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int res = 0,start = 1;;
        for (int i = 0; i < str.length()-1; i++) {
            if(str.charAt(i)=='-') continue;
            res += Integer.parseInt(Character.toString(str.charAt(i)))*start;
            start++;
        }
        res %= 11;
        String result  = new StringBuilder(str).deleteCharAt(str.length()-1).toString();
        if(res == 10){
            result = result + "X";
        }else {
            result = result + res ;
        }
        if(result.equals(str)){
            System.out.println("Right");
        }else {
            System.out.println(result);
        }
    }
}

#笔试##九江银行#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务