求组#4,#7红

P1055 [NOIP2008 普及组] ISBN 号码

tang_cu_pai_gu @ 2022-12-12 14:58:00

import java.util.Scanner;

public class P1055 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str=scan.next();
        StringBuilder sb = new StringBuilder(str);
        int sum = 0;
        for (int i = 0, j = 1; i < 13; i++, j++) {
            if (i == 1 || i == 5 || i == 11) {
                i++;
            }
            sum += ((int) (str.charAt(i))-48) * j;
            if (j == 9) {
                break;
            }
        }
        //System.out.println((int)(str.charAt(2)));
        //System.out.println(sum);
        if(sum%11==(int)(str.charAt(12)-48)){
            if(sum%11==10){
                sb.setCharAt(12,'X');
                str=sb.toString();
            }
            System.out.println("Right");
        }
        else{
            if(sum%11==10){
                sb.setCharAt(12,'X');
            }
            else {
                sb.setCharAt(12, (char) (sum % 11 + 48));
            }
           str=sb.toString();
           System.out.println(str);
        }
    }

}

|