解题思路: 字符串操作
注意事项: 注意识别码为 X 的特殊情况的处理
参考代码:
import java.util.Scanner; /** * 2021年2月16日 下午8:32:46 * @author praguetramp */ public class Main { public static void main(String []args) { Scanner in =new Scanner(System.in); while(in.hasNext()) { char ISBN[] =in.nextLine().toCharArray(); int cnt=1,last=0; for(int i=0;i<ISBN.length-1;i++) { if(ISBN[i]!='-') { last=(last+(ISBN[i]-'0')*cnt)%11; //计算识别码 cnt++; } } if(ISBN[12]=='X'&&last==10) //判断识别码为 X 的情况 System.out.println("Right"); else{ if(last==(ISBN[12]-'0')) System.out.println("Right"); else { if(last==10) ISBN[12]='X'; else ISBN[12]=(char)(last+'0'); for(char a:ISBN) System.out.print(a); System.out.println(); } } } in.close(); } }
0.0分
3 人评分
聪明的美食家 (C语言代码)浏览:1246 |
C语言训练-舍罕王的失算 (C语言代码)浏览:1033 |
C二级辅导-求偶数和 (C语言代码)浏览:625 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:665 |
简单的a+b (C语言代码)浏览:597 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:464 |
1128题解(返回值为数组的情况)浏览:450 |
Tom数 (C语言代码)浏览:725 |
Pascal三角 (C语言代码)浏览:641 |
A+B for Input-Output Practice (I) (C语言代码)浏览:426 |