Skip to content

Instantly share code, notes, and snippets.

@02015678
Created January 23, 2015 12:53
Show Gist options
  • Save 02015678/25344e4cfdc87dc099a4 to your computer and use it in GitHub Desktop.
Save 02015678/25344e4cfdc87dc099a4 to your computer and use it in GitHub Desktop.
NKOJ 1781: ISBN
Var
a:array[1..10]OF 0..10;
str:string;
n,i,s:integer;
Function cal(x,y:integer):integer;
Var
i:integer;
ans:integer;
Begin
ans:=0;
IF y>=x THEN For i:=x to y do inc(ans,a[i]*(11-i));
cal:=ans;
End;
Begin
s:=-1;
readln(str);
For i:=1 to 10 Do
Case str[i] OF
'0'..'9':a[i]:=ord(str[i])-ord('0');
'X':a[i]:=10;
'?':n:=i;
End;
IF n=10{如果第十位空缺,那么直接计算}
THEN s:=11-cal(1,9) mod 11
ELSE{否则,一一试探}
For i:=0 to 9 Do
Begin
a[n]:=i;
IF cal(1,10) mod 11=0
THEN s:=i;
End;
IF s=10
THEN writeln('X')
ELSE writeln(s);
End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment