/ Vijos / 讨论 / 问答 /

p1003怎么回事?

var ss,sss:string;
s,s1:array[1..206] of string;
suan:array[0..206] of longint;
n:longint;
t:array[1..260] of boolean;
opf:array[1..1000] of char;
ops:array[1..1000] of longint;
topf,tops:longint;
//
procedure init;
var i:longint;
c:char;
begin
assign(input,'p1003.in');assign(output,'p1003.out');
reset(input);rewrite(output);
readln(sss);
readln(n);
for i:=1 to n do readln(s[i])
end;
//
procedure stri(k:integer;var s:string);
var l:integer;
s1:string;
begin
while (pos('a',s)<>0) do
begin
l:=pos('a',s);
str(k,s1);
delete(s,l,1);insert(s1,s,l);
end;
end;
//
procedure pushf(c:char);
begin
inc(topf);opf[topf]:=c;
end;
//
procedure pushs(s:longint);
begin
inc(tops);ops[tops]:=s;
end;
//
function pops:longint;
begin
pops:=ops[tops];
dec(tops);
end;
//
function popf:char;
begin
popf:=opf[topf];
dec(topf);
end;
//
function jisuan(a,b:longint;c:char):longint;
var i:longint;
begin
case c of
'+':exit(a+b);
'-':exit(a-b);
'*':exit(a*b);
'^':begin
jisuan:=a;i:=1;
while i<>b do
begin
inc(i);jisuan:=jisuan*a;
end;
end;
end;
end;
//
function wei(c:char):integer;
begin
case c of
'-','+':exit(1);
'*':exit(2);
'^':exit(3);
')':exit(4);
'(':exit(0);
end;
end;
//
function exp(s:string):longint;
var i,l,p:longint;
j:longint;
begin
topf:=0;tops:=0;
while s<>'' do
begin
while s[1]=' ' do delete(s,1,1);l:=1;
while (s[l]>='0') and (s[l]<='9') do inc(l);
if (l=1) then
begin
if s[1]=')' then
begin
while opf[topf]<>'(' do pushs(jisuan(pops,pops,popf));
dec(topf);
end;
while (wei(s[1])<=wei(opf[topf])) and (topf>=1) and (opf[topf]<>'(') and (s[1]<>'(') do pushs(jisuan(pops,pops,popf));
if s[1]<>')' then pushf(s[1]);
end
else begin
val(copy(s,1,l-1),j,p);pushs(j);delete(s,1,l-1);
end;
if l=1 then delete(s,1,1);
end;
while topf<>0 do
pushs(jisuan(pops,pops,popf));
exit(ops[1]);
end;
//
procedure main;
var i,j:longint;
begin
for i:=1 to 20 do
begin
s1:=s;ss:=sss;
stri(i,ss);
for j:=1 to n do stri(i,s1[j]);
suan[0]:=exp(ss);
for j:=1 to n do
begin
suan[j]:=exp(s1[j]);
if suan[0]<>suan[j] then t[j]:=true;
end;
end;
end;
//
procedure print;
var i:longint;
begin
for i:=1 to n do
if not(t[i]) then write(chr(i+ord('A')-1));
close(output);
end;
//
begin
init;
main;
print;
end.

试了数据都对,为啥爆0

2 条评论

  • @ 2013-08-29 23:15:01

    去掉输出输入就30分

  • @ 2013-08-24 23:17:41

    让我来告诉你把!!哈哈哈

    我不会啊。。。。

  • 1