当前位置:网站首页>10007. ISBN号码
10007. ISBN号码
2022-06-11 01:16:00 【DXB2021】
每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字、1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”就是分隔符(键盘上的减号),最后一位是识别码,例如0-670-82162-4就是一个标准的ISBN码。ISBN码的首位数字表示书籍的出版语言,例如0代表英语;第一个分隔符“-”之后的三位数字代表出版社,例如670代表维京出版社;第二个分隔符后的五位数字代表该书在该出版社的编号;最后一位为识别码。
识别码的计算方法如下:
首位数字乘以1加上次位数字乘以2……以此类推,用所得的结果mod 11,所得的余数即为识别码,如果余数为10,则识别码为大写字母X。例如ISBN号码0-670-82162-4中的识别码4是这样得到的:对067082162这9个数字,从左至右,分别乘以1,2,...,9,再求和,即0×1+6×2+……+2×9=158,然后取158 mod 11的结果4作为识别码。
你的任务是编写程序判断输入的ISBN号码中识别码是否正确,如果正确,则仅输出“Right”;如果错误,则输出你认为是正确的ISBN号码。
输入格式:
只有一行,是一个字符序列,表示一本书的ISBN号码(保证输入符合ISBN号码的格式要求)。
输出格式:
只有一行,假如输入的ISBN号码的识别码正确,那么输出“Right”,否则,按照规定的格式,输出正确的ISBN号码(包括分隔符“-”)。
提示:
NOIP普及组2008
限制:
各个测试点1s
样例 1 :
输入: 0-670-82162-4
输出: Right
样例 2 :
输入: 0-670-82162-X
输出: 0-670-82162-4
C语言:
#include <stdio.h>
int main()
{
char isbn[13],right[13];
int temp1=1,sum=0;
scanf("%s",isbn);
for(int i=0;i<11;i++)
{
if(isbn[i]=='-')
continue;
if(isbn[i]>='0'&&isbn[i]<='9')
{
int temp2=isbn[i]-'0';
sum+=temp1*temp2;
temp1++;
}
}
if((sum%11)==isbn[13])
printf("Right");
else
{
for(int i=0;i<12;i++)
right[i]=isbn[i];
right[13]=sum%11;
printf("%s",right);
}
return 0;
}评测状态
答案错误 0
语言: C
用时: 0 ms 内存: 1088 kb 代码长度: 415
边栏推荐
- 渗透测试-安全服务体系+OWASP top 10
- 心态不能崩......
- Task04: String
- Understanding of pointers
- CRS-4544 & ORA-09925
- JS basic part hand exercises
- Internet of things final assignment - sleep quality detection system (refined version)
- Alibaba cloud Tianchi online programming training camp_ Task arrangement
- Fallible point--
- The largest kth element in the array
猜你喜欢

MD61计划独立需求导入BAPI【按日维度/动态模板/动态字段】

大厂测试员年薪30万到月薪8K,吐槽工资太低,反被网友群嘲?

InfoQ geek media's 15th anniversary solicitation | in depth analysis of container runtime Technology

Secret
![[music] playing city of the sky based on MATLAB [including Matlab source code 1874]](/img/cf/63b04080867e93ab2e00e2e21b37df.jpg)
[music] playing city of the sky based on MATLAB [including Matlab source code 1874]

In the past 10 years, from zero foundation testing to test architect, he has made himself successful

Epoll 原理及应用 && ET模式与LT模式

腾讯测试开发岗面试上机编程题
![[music] playing blue and white porcelain based on MATLAB [including Matlab source code 1873]](/img/cf/63b04080867e93ab2e00e2e21b37df.jpg)
[music] playing blue and white porcelain based on MATLAB [including Matlab source code 1873]

Introduction and practice of QT tcp/udp network protocol (I) TCP communication
随机推荐
JS basic part hand exercises
QT database learning notes (II) QT operation SQLite database
Implementing queues with stacks
Shell learning tutorial (super detailed and complete)
接口自动化核心知识点浓缩,为面试加分
[music] playing "over fire" based on MATLAB [including Matlab source code 1875]
Using an old mobile phone to build a server and achieve intranet penetration does not require root (I have personally tested the simplest one many times)
The diligent is the laziest
Seven principles that should be known by software testers
SAP SMARTFORMS换页打印自动判断
Oracle tablespaces, users, and authorization to users
In the past 10 years, from zero foundation testing to test architect, he has made himself successful
Wechat automatic red envelope grabbing source code
InfoQ 极客传媒 15 周年庆征文|容器运行时技术深度剖析
14:00面试,14:08就出来了 ,问的实在是太...
378. 有序矩阵中第 K 小的元素
14: 00 interview, came out at 14:08, the question is really too
贵金属白银和现货白银之间是什么关系
Blue Bridge Cup: the sixth preliminary round - "temperature recorder"
CRS-5017