当前位置:网站首页>Game improvement of smart people: Chapter 3 Lesson 1: ISBN (ISBN code)
Game improvement of smart people: Chapter 3 Lesson 1: ISBN (ISBN code)
2022-07-21 04:32:00 【Shining Sirius】
Here's a description , The title of this question does not match the test data , therefore —— I changed the title :
[ Problem description ]
Farmer John My cow likes reading , also Farmer John I found that his cow read some books about Natural Science , Produced more milk . He decided to replace the cheap novel with a book about Natural Science . Unfortunately , Some books fell into the mud , Their ISBN I can't see the code clearly .
ISBN code ( International Standard Book Number ) It is a code composed of ten Arabic numerals , Used to uniquely identify a book . If you want to verify ISBN Is the code correct , You have to multiply the first number 10, The second number multiplies 9, The third number multiplies 8, The fourth number multiplies 7…… Until the last number is multiplied 1, Add up these accumulations , If the number can be 11 to be divisible by ( That is to say 11 Multiple ) Words , Then this is a legal ISBN code .
for instance 0201103311 It's a legal ISBN code , because :
0×10 + 2×9 + 0×8 + 1×7 + 1×6 + 0×5 + 3×4 + 3×3 + 1×2 + 1×1
The first nine numbers are 0 – 9 Between . occasionally , The last number has to be taken 10, Then let's write the last number in capital X( It's not called numbers at this time , ha-ha ), such as 156881111X It's also a legal ISBN code . Your task is to give you a number lost ISBN After a yard , Identify the missing number . For missing numbers “ ?” Express .
[ Input format ]
One 10 It's made up of two numbers ISBN code , It includes “ ?” Represents the missing number .
[ Output format ]
Lost ISBN code (0-9 Or in capitals X). If it says “ ?” There are no numbers that can make it legal ISBN code , The output -1.
[ sample input ]
02011?3311
[ sample output ]
0
well , And then code :
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int i,k,n,t,s=0;
string a;
bool f=1;
int main()
{
freopen ("isbn.in","r",stdin);
freopen ("isbn.out","w",stdout);
cin >>a;
for (i=0;i<10;i++)
{
if (a[i]=='?')
k=10-i;
else if (a[i]>='0' && a[i]<='9')
{
s+=(a[i]-48)*(10-i);
}
else
s+=10;
}
t=(s/11+1)*11-s;
if (s!=0)
{
if (s%11==0)
cout <<0;
else if (k!=1)
{
for (i=0;(t+i*11)/k<10;i++)
if ((t+i*11)%k==0)
{
cout <<(t+i*11)/k;
f=0;
break;
}
if (f)
cout <<-1;
}
else
{
if (t<10)
cout <<t;
else if (t==10)
cout <<"X";
}
}
else
cout <<-1;
fclose(stdin);
fclose(stdout);
return 0;
}
Okay , The code is easy to understand , Don't forget to like it .
边栏推荐
猜你喜欢
随机推荐
HCIA知识总结
STM32学习(2)GPIO
ENSP—NAT综合实验
Shell的各种变量和变量运算
DHCP概述及详细的DHCP服务器部署
SNAT and DNAT
DHCP配置
Quickly understand shell functions and arrays
动态路由协议—RIP实验
02 linear structure 4 pop sequence (simulation of stack in and stack out)
Pycharm suddenly cannot connect to the remote server
DHCP overview and detailed DHCP server deployment
北京双线机房的优缺点分析
Server firewall software iptables
One bite of Stream(4)
Comparative analysis of server hosting and self built computer rooms
yum本地仓库
Analysis of advantages and disadvantages of Beijing double line machine room
Shell循环语句详解--while、until循环
DHCP principle and configuration