import java.util.Scanner;
public class _20131202 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
String str1 = str.replace("-", "");
char[] ch = str1.toCharArray();
int sum = 0;
char c='0';
for (int i = 0; i < 9; i++) {
sum += (ch[i] - 48) * (i + 1);
}
sum = sum % 11;
if(sum==10){
c='X';
}else{
c=(char)(sum+48);
}
if (c== ch[ch.length-1]) {
System.out.println("Right");
}else {
System.out.println(str.substring(0, 12) +c);
}
}
70分
这个是我一开始做得代码很啰嗦,但是不知道为什么是错误的,求指教
import java.util.Scanner;
public class _20131202 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] content = input.split("-");
int one = Integer.parseInt(content[0]);
int two = Integer.parseInt(content[1]);
int three = Integer.parseInt(content[2]);
int sum = one;
int count = 10;
for (int i = 4; i > 1; i--) {
sum += two % count * i;//698=6*1+9*2+8*3
two = two / count;
}
for (int j = 9; j > 4; j--) {
sum += three % count * j;
three = three / count;
}
int last1 = sum % 11;
String out = input.substring(0, 12);
int last=0;
//这边处理有点啰嗦
if (!content[3].equalsIgnoreCase("X")) {
last = Integer.parseInt(content[3]);
if (last==10){
System.out.println(out + "X");
}else if (last==last1){
System.out.println("Right");
}else {
System.out.println(out + String.valueOf(last1));
}
}else {
if (last1==10){
System.out.println("Right");
}else {
System.out.println(out + String.valueOf(last1));
}
}
}
}
CCF(Java)序列之ISBN码@TOCCCF(Java)序列之ISBN码(_20131202)100分import java.util.Scanner;public class _20131202 { public static void main(String[] args) { Scanner in = new Scanner(System.in); ...