Created
January 23, 2015 12:54
-
-
Save 02015678/845a6175083db1542213 to your computer and use it in GitHub Desktop.
NKOJ 1781: ISBN Liuhy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program ISBN; | |
uses CRT; | |
var | |
d:array [1..10] of integer; | |
i,unk,sumn,ans,t:integer; | |
b:boolean; s:string; | |
begin | |
sumn:=0; | |
readln(s); | |
for i:=1 to 10 do | |
begin | |
case s[i] of | |
'0'..'9':begin b:=true; d[i]:=ord(s[i])-48; end; | |
'X':begin b:=true; d[i]:=10; end; | |
'?':begin unk:=i; b:=false; end; | |
end; | |
if b then inc(sumn,(11-i)*d[i]); | |
end; | |
ans:=-1; | |
if unk = 10 then t:=10 else t:=9; | |
for i:=0 to t do | |
if (sumn+(11-unk)*i) mod 11 = 0 then ans:=i; | |
assign(output,'a.txt'); | |
rewrite(output); | |
if ans = 10 then writeln('X') else writeln(ans); | |
close(output); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment