题解 | #[NOIP2008]ISBN号码#
[NOIP2008]ISBN号码
http://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5
import java.util.Scanner;
// 注意:10要和X等价
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int count = 1;
int sum = 0;
for (int i = 0; i < s.lastIndexOf("-"); i ++) {
if (s.charAt(i) == '-') {
continue;
}
// 字符会按照ASCII码转换
sum += Integer.valueOf(s.charAt(i) + "") * count;
count ++;
}
int id = sum % 11;
String idx = (id == 10 ? "X" : id + "");
String oriId = s.substring(s.lastIndexOf("-") + 1);
if (idx.equals(oriId)) {
System.out.println("Right");
} else {
System.out.println(s.substring(0, s.lastIndexOf("-") + 1) + idx);
}
}
}