解题思路: 字符串操作
注意事项: 注意识别码为 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语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:517 |
程序员的表白 (C语言代码)浏览:653 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:660 |
求组合数 (C语言代码)浏览:1152 |
WU-链表数据求和操作 (C++代码)浏览:1310 |
The 3n + 1 problem (C语言代码)浏览:548 |
1157题解浏览:711 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:552 |
1074(纳闷了,答案错误,求指教)浏览:362 |
简单的a+b (C语言代码)浏览:645 |