当前位置:网站首页>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;
}
边栏推荐
- Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
- IDEA 2021.3. X cracking
- SAP HR reward and punishment information export
- Access database query all tables SQL
- C simple question one
- SAP HR family member information
- 【7.5】15. 三数之和
- @Configuration注解的详细介绍
- Live server usage
- Dependency injection
猜你喜欢
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
[STM32 + esp-12s connect Tencent cloud IOT development platform 1] creation of cloud platform and burning of at firmware
[stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
Extended tree (I) - graphic analysis and C language implementation
Live-Server使用
B_QuRT_User_Guide(37)
Map operation execution process
Take you hand in hand to build Eureka server with idea
S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
随机推荐
Windows set redis to start automatically
SAP HR labor contract information 0016
SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration
Where are you going
Boost regex library source code compilation
Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
What if once again forgets the login password of raspberry pie? And you don't have a monitor yet! Today, I would like to introduce a method
Map operation execution process
648. Word replacement
Come on, brother
2022第六季完美童模陕西总决赛圆满落幕
[compilation principle] lexical analysis design and Implementation
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
Open source hardware small project: anxinco esp-c3f control ws2812
【实验分享】通过Console口登录到Cisco设备
B_QuRT_User_Guide(39)
B_QuRT_User_Guide(40)
SAP memory parameter tuning process
Understand TCP's three handshakes and four waves with love
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels