标签:acea ccf else sum string substring ast rgs mamicode
就是把-去掉,然后验证,只需要改最后一位。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();//原字符串
String substr = str.replaceAll("-", "");//去掉-
int sum = 0;
int len = substr.length();
int last;
for(int i = 0;i<len-1;i++) {
sum += (i+1) * Integer.parseInt(substr.substring(i, i+1));
}
if(substr.substring(len-1, len).equals("X")) {
last = 10;
}else {
last = Integer.parseInt(substr.substring(len-1, len));
}
if(sum % 11 == last) {
System.out.println("Right");
}else {
if(sum % 11 == 10) {
System.out.println(str.substring(0,str.length()-1) + "X");
}else {
System.out.println(str.substring(0, str.length()-1) + sum%11);
}
}
sc.close();
}
}
标签:acea ccf else sum string substring ast rgs mamicode
原文地址:https://www.cnblogs.com/yu-jiawei/p/12316184.html