# 外星生命(et.pas/in/out)

(et.pas/in/out)

Problem

Input

Output

Sample Input

000023*000011=002093

Sample Output

1

==========================

1.枚举每一位判断是否和给出的相同..

2.模拟高精乘....

--------------

==============================

{
ID:jie19952
PROG:
LANG:PASCAL
}
var
st:string;
ans:longint;
a,b,c:array[1..6]of longint;
procedure init;
begin
assign(input,'et.in');
assign(output,'et.out');
reset(input); rewrite(output);
end;

procedure terminate;
begin
close(input); close(output);
halt;
end;

procedure pre;
var
i:longint;
begin
for i:=1 to 6 do
begin
a[i]:=ord(st[i])-ord('0');
b[i]:=ord(st[7+i])-ord('0');
c[i]:=ord(st[14+i])-ord('0');
end;
end;

procedure dfs(l,jw,m:longint);
var
x,y:longint;
x0,y0:longint;
sum:longint;
i:longint;
begin
if m>=ans then exit;
if l=0 then begin ans:=m; exit; end;
x0:=a[l]; y0:=b[l];
for x:=0 to 9 do
for y:=0 to 9 do
begin
if x0<>x then inc(m);
if y0<>y then inc(m);
a[l]:=x; b[l]:=y;
sum:=jw;
for i:=l to 6 do
inc(sum,a[i]*b[l+6-i]);
if sum mod 10<>c[l] then inc(m);

dfs(l-1,sum div 10,m);

if sum mod 10<>c[l] then dec(m);
if x0<>x then dec(m);
if y0<>y then dec(m);
end;
a[l]:=x0; b[l]:=y0;
end;

procedure main;
begin
ans:=6;
dfs(6,0,0);
writeln(ans);
end;

begin
init;
pre;
main;
terminate;
end.


• 本文已收录于以下专栏：

举报原因： 您举报文章：外星生命(et.pas/in/out) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)