在linux下fpc 1.0.10能否成功编译这个程序(pascal),有linux的朋友帮个忙,事情紧急.谢谢.
程序如下:
program equal;
const inf='equal.in';
ouf='equal.out';
var n:integer;
p,np:array[0..26] of string;
answ:array[0..26,1..9] of Int64;
ok:array[1..26] of boolean;
procedure reads;
var i,j:integer;
st,tmp:string;
begin
assign(input,inf);
reset(input);
readln(st);
tmp:='';
for j:=1 to length(st) do
begin
if st[j]<>' ' then
tmp:=tmp+st[j];
end;
np[0]:=tmp;
readln(n);
for i:=1 to n do
begin
readln(st);
tmp:='';
for j:=1 to length(st) do
begin
if st[j]<>' ' then
tmp:=tmp+st[j];
end;
np[i]:=tmp;
end;
close(input);
end;
procedure change(x:char);
var i,j:integer;
begin
p:=np;
for i:=0 to n do
for j:=1 to length(np[i]) do
if p[i][j]='a' then p[i][j]:=x;
end;
function yx(x:char):integer;
begin
case x of
'+','-' : exit(1);
'*' : exit(2);
'^' : exit(3);
end;
end;
function ans(x:string):Int64;
var i,k,l,j:integer;
lowch:char;
low:integer;
key:Int64;
code:integer;
s1,s2:string;
begin
k:=0; l:=0;
while (x[1]='(') and (l=0) do
begin
l:=1;
for j:=1 to length(x)-1 do
begin
if x[j]='(' then inc(k);
if x[j]=')' then dec(k);
if k=0 then break;
end;
if (k=1)and(j=length(x)-1) then
begin
x:=copy(x,2,length(x)-2);
l:=0; K:=0;
end;
end;
val(x,key,code);
if code=0 then exit(key);
lowch:='^'; low:=0; k:=0;
for j:=1 to length(x) do
begin
if x[j]='(' then inc(k);
if x[j]=')' then dec(k);
if (k=0) and (yx(x[j])<=yx(lowch)) then
begin
lowch:=x[j];
low:=j;
end;
end;
s1:=copy(x,1,low-1);
s2:=copy(x,low+1,length(x)); case lowch of
'+' : exit(ans(s1)+ans(s2));
'-' : exit(ans(s1)-ans(s2));
'*' : exit(ans(s1)*ans(s2));
'^' : exit(power(ans(s1),ans(s2)));
end;
end;
procedure process;
var c,i,j:integer;
begin
for c:=1 to 9 do
begin
change(chr(48+c));
for i:=0 to n do
answ[i][c]:=ans(p[i]);
end;
fillchar(ok,sizeof(ok),true);
for i:=1 to n do
begin
for j:=1 to 9 do
begin
if answ[i][j]<>answ[0][j] then
begin
ok[i]:=false;
end;
end;
end;
assign(output,ouf);
rewrite(output);
for i:=1 to n do
if ok[i] then write(chr(64+i));
close(output);
end;
begin
reads;
process;
end.
程序如下:
program equal;
const inf='equal.in';
ouf='equal.out';
var n:integer;
p,np:array[0..26] of string;
answ:array[0..26,1..9] of Int64;
ok:array[1..26] of boolean;
procedure reads;
var i,j:integer;
st,tmp:string;
begin
assign(input,inf);
reset(input);
readln(st);
tmp:='';
for j:=1 to length(st) do
begin
if st[j]<>' ' then
tmp:=tmp+st[j];
end;
np[0]:=tmp;
readln(n);
for i:=1 to n do
begin
readln(st);
tmp:='';
for j:=1 to length(st) do
begin
if st[j]<>' ' then
tmp:=tmp+st[j];
end;
np[i]:=tmp;
end;
close(input);
end;
procedure change(x:char);
var i,j:integer;
begin
p:=np;
for i:=0 to n do
for j:=1 to length(np[i]) do
if p[i][j]='a' then p[i][j]:=x;
end;
function yx(x:char):integer;
begin
case x of
'+','-' : exit(1);
'*' : exit(2);
'^' : exit(3);
end;
end;
function ans(x:string):Int64;
var i,k,l,j:integer;
lowch:char;
low:integer;
key:Int64;
code:integer;
s1,s2:string;
begin
k:=0; l:=0;
while (x[1]='(') and (l=0) do
begin
l:=1;
for j:=1 to length(x)-1 do
begin
if x[j]='(' then inc(k);
if x[j]=')' then dec(k);
if k=0 then break;
end;
if (k=1)and(j=length(x)-1) then
begin
x:=copy(x,2,length(x)-2);
l:=0; K:=0;
end;
end;
val(x,key,code);
if code=0 then exit(key);
lowch:='^'; low:=0; k:=0;
for j:=1 to length(x) do
begin
if x[j]='(' then inc(k);
if x[j]=')' then dec(k);
if (k=0) and (yx(x[j])<=yx(lowch)) then
begin
lowch:=x[j];
low:=j;
end;
end;
s1:=copy(x,1,low-1);
s2:=copy(x,low+1,length(x)); case lowch of
'+' : exit(ans(s1)+ans(s2));
'-' : exit(ans(s1)-ans(s2));
'*' : exit(ans(s1)*ans(s2));
'^' : exit(power(ans(s1),ans(s2)));
end;
end;
procedure process;
var c,i,j:integer;
begin
for c:=1 to 9 do
begin
change(chr(48+c));
for i:=0 to n do
answ[i][c]:=ans(p[i]);
end;
fillchar(ok,sizeof(ok),true);
for i:=1 to n do
begin
for j:=1 to 9 do
begin
if answ[i][j]<>answ[0][j] then
begin
ok[i]:=false;
end;
end;
end;
assign(output,ouf);
rewrite(output);
for i:=1 to n do
if ok[i] then write(chr(64+i));
close(output);
end;
begin
reads;
process;
end.
解决方案 »
- DELPHI RXRICHEDIT插入GIF后闪烁
- 送分!当家人休闲(桑拿)会所管理系统发布
- 高手1分钟就解决了
- 客户要在生产流水拉装条码扫描仪,对通过的产品进行扫描,如果扫到就放行并录入电脑,否则不放行(加装门禁机)
- adoquery使用参数查询错误的错误!“list index out of bounds(2)”!!!晕啊!!!
- 如何铺获鼠标滑轮事件
- 菜鸟问题
- 并于一个CLIENT端与多个SERVER端之间的通信问题?
- Access数据库联接问题!
- 如何获得http://xxx.xxx.xxx.com/xxx.jpg文件并显示?
- 一个稍微有点格路得问题,希望各位帮忙,如果解决另有高分相送
- 我还活着……
我这没法试(我没LINUX).
又急于知道结果.
谢谢。
但是不知道LINUX下的情况。
再次感谢。
请朋友们帮忙。
在Mandrake 9.1下通过,不过是用的Kylix,没有装FPC。:)