PersonalCorpus 版 (精华区)
寄信人: sino (蚱蜢舟)
标 题: 1186
发信站: 哈工大紫丁香 (2002年03月23日16:44:41 星期六)
来 源: mtlab4.hit.edu.cn
171303 08:47:17 23 Mar 2002
Bozhang,HIT,P.R.China 1186 Pascal Accepted 0.02 sec 86K
type settype = array[0..100] of integer;
var
names:array[1..100] of string;
check,full:settype;
i,n,tot_e:integer;
f:boolean;
s,t:string;
function GetID(s:string):integer;
var i:integer;
begin
for i:=1 to tot_e do if s=names[i] then begin
result:=i; exit;
end;
result:=0;
end;
procedure MakeTable(var s:string);
var i,j,k:integer;
begin
i:=1;
while i<=length(s) do begin
if (s[i]>='A') and (s[i]<='Z') then begin
j:=i+1; while (j<=length(s)) and (s[j]>='a') and (s[j]<='z') do
inc(j);
k:=GetID(copy(s,i,j-i));
if k=0 then begin
inc(tot_e);
names[tot_e]:=copy(s,i,j-i);
end;
end;
inc(i);
end;
end;
procedure Calc(var des:settype;s:string);
var i,j,k,m:integer;
temp:settype;
begin
if length(s)=0 then exit;
case s[1] of
'0'..'9':begin
j:=2; while (s[j]>='0') and (s[j]<='9') do inc(j);
val(copy(s,1,j-1),i,k);
delete(s,1,j-1);
s:=s+'+';
fillchar(temp,sizeof(temp),0);
Calc(temp,copy(s,1,pos('+',s)-1));
for j:=0 to tot_e do des[j]:=des[j]+temp[j]*i;
delete(s,1,pos('+',s));
while length(s)>0 do begin
fillchar(temp,sizeof(temp),0);
Calc(temp,copy(s,1,pos('+',s)-1));
for j:=0 to tot_e do des[j]:=des[j]+temp[j];
delete(s,1,pos('+',s));
end;
end;
'A'..'Z':begin
j:=2; while (j<=length(s)) and (s[j]>='a') and (s[j]<='z') do in
c(j);
i:=GetID(copy(s,1,j-1));
delete(s,1,j-1);
if (length(s)>0) and (s[1]>='0') and (s[1]<='9') then begin
j:=2; while (j<=length(s)) and (s[j]>='0') and (s[j]<='9') d
o inc(j);
val(copy(s,1,j-1),k,m);
inc(des[i],k);
delete(s,1,j-1);
Calc(des,s);
end else begin
inc(des[i]);
Calc(des,s);
end;
end;
'+':begin
delete(s,1,1);
Calc(des,s);
end;
'(':begin
k:=1; j:=2;
while k<>0 do begin
if s[j]='(' then inc(k) else if s[j]=')' then dec(k);
inc(j);
end;
fillchar(temp,sizeof(temp),0);
Calc(temp,copy(s,2,j-3));
delete(s,1,j-1);
if 0<length(s) then if (s[1]>='0') and (s[1]<='9') then begin
j:=2; while (j<=length(s)) and (s[j]>='0') and (s[j]<='9') d
o inc(j);
val(copy(s,1,j-1),i,k);
for k:=0 to tot_e do temp[k]:=temp[k]*i;
delete(s,1,j-1);
end;
for k:=0 to tot_e do des[k]:=des[k]+temp[k];
Calc(des,s);
end;
end;
end;
begin
readln(s);
tot_e:=0; MakeTable(s);
fillchar(full,sizeof(full),0);
Calc(full,s);
readln(n);
while n>0 do begin
dec(n); readln(t);
fillchar(check,sizeof(check),0);
Calc(check,t);
f:=true;
for i:=0 to tot_e do if check[i]<>full[i] then begin f:=false; break
end;
if f then writeln(s,'==',t) else writeln(s,'!=',t);
end;
end.
--
... 洪七公笑道:“娃娃,你媳妇儿煮菜的手艺天下第一,你这一生可享定了福。
他妈的,我年轻时怎么没撞见这样好本事的女人?”言下似乎深以为憾。...
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: mtlab4.hit.edu.cn]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.320毫秒