import java.util.Scanner; public class Main { public static void main(String[] args) { // write your code here Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] weight={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; int[] zvalue={0,1,2,3,4,5,6,7,8,9,10}; char[] mvalue={‘1‘,‘0‘,‘X‘,‘9‘,‘8‘,‘7‘,‘6‘,‘5‘,‘4‘,‘3‘,‘2‘}; String[] num=new String[n]; for (int i=0;i<n;i++){ num[i]=sc.next(); } int sum; int wei; boolean b; int count=0; for (int i=0;i<n;i++){ wei=0; sum=0; b=false; //判断前17位是否存在非数字的字符,有的话,输出 for (int j=0;j<num[i].length();j++){ if (num[i].charAt(j)>=‘0‘&&num[i].charAt(j)<=‘9‘&&j<num[i].length()-1){ sum=sum+Integer.parseInt(num[i].charAt(j)+"")*weight[j]; b=true; }else if (b==true&&j==num[i].length()-1){ break; } else{ count++; System.out.println(num[i]); break ; } } wei=sum%11; for (int k=0;k<11;k++){ if (wei==zvalue[k]){ if (num[i].charAt(num[i].length()-1)!=mvalue[k]){ count++; System.out.println(num[i]); break ; }else{ if (count==0&&i==n-1){ System.out.println("All passed"); break; } } } } } } }
牛客满分,pta扣5分,蓝瘦,一个测试点错误
原文:https://www.cnblogs.com/zhuzehua/p/9795294.html