解题思路: 字符串操作
注意事项: 注意识别码为 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 人评分
Tom数 (C语言代码)浏览:735 |
不容易系列2 (C语言代码)浏览:589 |
蚂蚁感冒 (C语言代码)浏览:1319 |
简单的a+b (C语言代码)浏览:531 |
字符逆序 (C语言代码)浏览:504 |
拆分位数 (C语言代码)浏览:514 |
筛排处理 (C语言代码)浏览:782 |
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:498 |
A+B for Input-Output Practice (II) (C语言代码)浏览:595 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:466 |