ljt0203 @ 2023-06-01 00:45:33
import java.util.Objects;
import java.util.Scanner;
import static java.lang.System.in;
public class Main {
public static void main(String[] args) {
int t = 0, k = 1;
Scanner scanner = new Scanner(in);
String str = scanner.nextLine();
String regularExpression = "\\d{1}\\-\\d{3}+\\-\\d{5}\\-\\d{1}";
if (str.matches(regularExpression)) {
String ss[] = new String[]{str};
char[] s1=str.toCharArray();
for (int i=0;i<ss.length;i++){
if(s1[i]=='-')continue;
t+=s1[i]*k;
k++;
}
int w=t%11;
String q=String.valueOf(w);
String p= String.valueOf(str.charAt(12));
if (Objects.equals(q,p)){
System.out.println("Right");
}else {
StringBuilder sb = new StringBuilder(str);
sb.replace(str.length() - 1, str.length(), q);
System.out.println(sb);
}
}
}
}
by ljt0203 @ 2023-06-01 00:59:39
import java.util.Objects;
import java.util.Scanner;
import static java.lang.System.in;
public class Main {
public static void main(String[] args) {
int t=0,k=1;
Scanner scanner = new Scanner(in);
String str=scanner.nextLine();
String ss[] = new String[]{str};
char[] s1=str.toCharArray();
for (int i=0;i<ss.length;i++){
if(s1[i]=='-')continue;
t+=s1[i]*k;
k++;
}
int w=t%11;
String q=String.valueOf(w);
String p= String.valueOf(str.charAt(12));
if (Objects.equals(q,p)){
System.out.println("Right");
}else {
StringBuilder sb = new StringBuilder(str);
sb.replace(str.length() - 1, str.length(), q);
System.out.println(sb);
}
}
}
by ljt0203 @ 2023-06-01 01:01:20
@ljt0203 搞错了,是这段,上面那的是我加了个判定后的,结果只有1和3是AC
by ljt0203 @ 2023-06-01 20:08:56
已解决