这题唯一要注意的就是,一个字符想变成数字运算,那就就得 - ‘0’;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.next();
int sum = 0, count = 1;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '-') {
continue;
}
if (i == str.length() - 1) {
sum = sum % 11;
if (sum == 10) {
if (str.charAt(i) == 'X') {
System.out.println("Right");
} else {
str = str.substring(0, i);
System.out.println(str + 'X');
}
break;
}
if (sum == str.charAt(i) - '0') {
System.out.println("Right");
} else {
str = str.substring(0, i);
System.out.printf("%s%d", str, sum);
}
break;
}
sum += (str.charAt(i) - '0') * count;
count++;
}
}
}
原题链接:http://118.190.20.162/view.page?gpid=T4