当前位置:网站首页>P1055 [noip2008 popularization group] ISBN number
P1055 [noip2008 popularization group] ISBN number
2022-07-07 23:40:00 【Yuesi】
P1055 -NOIP2008 Popularization group -ISBN number
Every book officially published has a ISBN The number corresponds to ,ISBN Code includes 9 Digit number 、1 Bit ID and 3 Bit separator , The format is as follows x-xxx-xxxxx-x, Symbols - It's the separator ( The minus sign on the keyboard ), The last one is the identification number , for example 0-670-82162-4 It's a standard ISBN code .ISBN The first digit of the code indicates the language of publication of the book , for example 0 For English ; First separator - The next three figures represent the publisher , for example 670670 On behalf of Viking press ; The five digits after the second separator represent the number of the book in the publishing house ; The last digit is the identification number .
The identification code is calculated as follows :
Multiply the first number by 1 Multiply the last digit by 2…… And so on , Use the results mod 11, The remainder obtained is the identification code , If the remainder is 1010, The identification code is capital letters XX. for example ISBN number 0-670-82162-4 Identification code in 4 This is how I got : Yes 067082162 this 99 A digital , From left to right , Times, respectively, 1,2,…,9 And then sum up , namely 0×1+6×2+……+2×9=1580×1+6×2+……+2×9=158, And then take 158 mod 11 Result 4 As an identification number .
Your task is to write a program to judge the input ISBN Is the identification number correct , If correct , Only output Right; If the error , Then output what you think is correct ISBN number .
Input format
A character sequence , For a book ISBN number ( Make sure the input matches ISBN Format requirements for number ).
Output format
a line , If you type ISBN The ID of the number is correct , Then output Right, otherwise , In the prescribed form , Output correct ISBN number ( Include separator -).
I/o sample
Input #1
0-670-82162-4
Output #1
Right
Input #2
0-670-82162-0
Output #2
0-670-82162-4
explain / Tips
2008 First question of popularization group
It's easy to get wrong :
%d What you read is not a number
Often make such common sense mistakes unintentionally
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
cin>>a;//string General way of reading in
int sum=0,num=1;
for(int i=0;i<13;i++){
if(i!=1&&i!=5&&i!=11&&i!=12){
// remove - And identification code
sum+=(a[i]-'0')*num;
num++;
}
}
sum=sum%11;
if(sum==10){
if(a[12]=='X'){
printf("Right\n");
}else{
for(int i=0;i<12;i++){
printf("%c",a[i]);
}
printf("X\n");
}
}else{
if(sum==(a[12]-'0')){
printf("Right\n");
}else{
for(int i=0;i<12;i++){
printf("%c",a[i]);
}
printf("%d\n",sum);
}
}
return 0;
}
边栏推荐
- B_QuRT_User_Guide(37)
- 648. Word replacement
- Interface
- Summary of common methods of object class (September 14, 2020)
- B_QuRT_User_Guide(39)
- ESP at installation esp8266 and esp32 versions
- Ora-01741 and ora-01704
- How can we make money by making video clips from our media?
- 数据分析系列 之3σ规则/依据拉依达准则来剔除异常值
- ASP. Net query implementation
猜你喜欢
![Balanced binary tree [AVL tree] - insert, delete](/img/1f/cd38b7c6f00f2b3e85d4560181a9d2.png)
Balanced binary tree [AVL tree] - insert, delete

Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels

B_QuRT_User_Guide(36)

Progress broadcast | all 29 shield machines of Guangzhou Metro Line 7 have been launched

UE4_ Ue5 combined with Logitech handle (F710) use record

UE4_ Ue5 panoramic camera

Pycharm essential plug-in, change the background (self use, continuous update) | CSDN creation punch in

B_QuRT_User_Guide(38)

激光slam学习(2D/3D、偏实践)

电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
随机推荐
Ora-02437 failed to verify the primary key violation
B_ QuRT_ User_ Guide(39)
0-1 knapsack problem
保证接口数据安全的10种方案
Installing gradle
C method question 2
Right click the idea file to create new. There is no solution to create new servlet
UE4_ Use of ue5 blueprint command node (turn on / off screen response log publish full screen display)
8.31 Tencent interview
aws-aws help报错
KeePass realizes automatic input of web pages
PCB wiring rules of PCI Express interface
postgis学习
Markdown
SAP HR social work experience 0023
The for loop realizes 1-100 addition and eliminates the 4-digit tail number
Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
ASP. Net query implementation
Come on, brother
B_QuRT_User_Guide(39)