POJ 2190(模拟策略)

来源:互联网 发布:淘宝抢拍器哪个最好 编辑:程序博客网 时间:2024/06/05 11:54

Language:
ISBN
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13962 Accepted: 4898

Description

ISBN码满足:(10*A1+9*A2+..+1*A10) mod 11=0
A10是效验码,若它为10,则以X代替,其它位都为0..9的数字
 现在给你一个效验码,但是其中一位看不清,请求出这一位。

Input

1行ISBN码,‘?'表示看不清

Output

输出那一位,无解输-1.

Sample Input

15688?111X

Sample Output

1

Source

USACO 2003 Fall Orange

这题就是模拟,模拟最重要的是细节,本题值得注意的细节:

1.某1位为0的情况.

2.其它位的乘积和是11的倍数.

3.某1位为X的情况.

4.无解.

5.其它位的乘积和包含'X'.

Program ISBN;const   n=10;   F=11;var   s:string;   i,p,ans:longint;begin   ans:=0;   readln(s);   if s[n]='X' then s[n]:=char(58);   p:=pos('?',s);   for i:=1 to n do      if i<>p then inc(ans,(ord(s[i])-48)*(10-i+1));   // ans +p*? mod 11 =0   ans:=ans mod F;   ans:=(F-ans) mod F;   for i:=0 to n do   begin      if ((11-p)*i) mod F=ans then      begin         if (p=n) and (i=10) then begin writeln('X'); halt; end;         if (i<10) then begin writeln(i);   halt; end;      end;   end;   writeln('-1');end.