当前位置:网站首页>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;
}
边栏推荐
- Anxinco esp32-a1s development board is adapted to Baidu dueros routine to realize online voice function
- Understand TCP's three handshakes and four waves with love
- MongoDB快速入门
- 企业应用需求导向开发之人力部门,员工考勤记录和实发工资业务程序案例
- 【路径规划】使用垂距限值法与贝塞尔优化A星路径
- 二叉排序树【BST】——创建、查找、删除、输出
- Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)
- How can we make money by making video clips from our media?
- Installing gradle
- Take you hand in hand to build Eureka client with idea
猜你喜欢
Dataguard 主备清理归档设置
[stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
Take you hand in hand to build Eureka client with idea
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
C # exchange number, judge to pass the exam
建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置
[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
ping报错:未知的名称或服务
[experiment sharing] log in to Cisco devices through the console port
Get started with mongodb
随机推荐
Markdown
8.31 Tencent interview
2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
企业应用需求导向开发之人力部门,员工考勤记录和实发工资业务程序案例
Three questions TDM
Navicat connects Oracle
How can we make money by making video clips from our media?
0-1 knapsack problem
Dependency injection 2 advantage lifecycle
C语言学习
Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
【路径规划】使用垂距限值法与贝塞尔优化A星路径
[stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
Oracle statistics by time
B_ QuRT_ User_ Guide(39)
S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
Boost regex library source code compilation
Map operation execution process
One week learning summary of STL Standard Template Library