关于Pascal转c++
  • 板块灌水区
  • 楼主_mazetorches
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/10/29 15:48
  • 上次更新2023/11/5 09:35:48
查看原帖
关于Pascal转c++
149219
_mazetorches楼主2020/10/29 15:48

老师给我们考了一场考试,但题解代码是以pascal的形式发放的

所以请问各位大佬有什么能将pascal语言转成c++语言的工具吗?

附代码:

program quarrel_lu;

var
   next,num:array[-20000..20000]of longint;
   a:array[0..500]of longint;
   q,l:array[0..250000,1..3]of longint;
   don:array[0..500,0..500,0..1]of boolean;
   step,la:array[0..500,0..500,0..1]of longint;
   tt,ans,n,m,i,x,y,k,cnt:longint;


procedure add(x,y:longint);
begin
     inc(tt);
     next[tt]:=a[x];num[tt]:=y;a[x]:=tt;
     next[-tt]:=a[y];num[-tt]:=x;a[y]:=-tt;
end;

function spfa:longint;
var st,en,p1,p2:longint;
begin
     q[1,1]:=1;q[1,2]:=n;q[1,3]:=0;
     don[1,n,0]:=true;step[1,n,0]:=0;
     st:=0;en:=1;
     repeat
           inc(st);
           if q[st,3]=1 then begin
               p1:=a[q[st,2]];
               while p1<>0 do begin
                     if  (q[st,1]<>num[p1])and not don[q[st,1],num[p1],0] then begin
                         inc(en);
                         q[en,1]:=q[st,1];q[en,2]:=num[p1];q[en,3]:=0;
                         don[q[st,1],num[p1],0]:=true;
                         step[q[st,1],num[p1],0]:=step[q[st,1],q[st,2],1];
                         la[q[en,1],q[en,2],0]:=la[q[st,1],q[st,2],1];
                         if (q[en,1]=n)and(q[en,2]=1) then exit(step[q[en,1],q[en,2],0]);
                     end;
                     p1:=next[p1];
               end;
           end else begin
               p1:=a[q[st,1]];
               while p1<>0 do begin
                     if  not don[num[p1],q[st,2],1] then begin
                         inc(en);
                         q[en,1]:=num[p1];q[en,2]:=q[st,2];q[en,3]:=1;
                         don[num[p1],q[st,2],1]:=true;
                         step[num[p1],q[st,2],1]:=step[q[st,1],q[st,2],0]+1;
                         la[q[en,1],q[en,2],1]:=st;
                     end;
                     p1:=next[p1];
               end;
           end;
     until st>=en;
     exit(-1);
end;

begin
	assign(input,'quarrel.in');reset(input);
	assign(output,'quarrel.out');rewrite(output);
     readln(n,m);
     for i:=1 to m do begin
         readln(x,y);
         add(x,y);
     end;
     ans:=spfa;
     writeln(ans);
     if ans>0 then begin
        k:=la[n,1,0];
        while k>0 do begin
              inc(cnt);
              l[cnt]:=q[k];
              k:=la[q[k,1],q[k,2],0];
        end;
        for i:=cnt downto 1 do write(l[i,1],' ');
        writeln(n);
        for i:=cnt downto 1 do write(l[i,2],' ');
        writeln(1);
     end;
	close(input);close(output);
end.


2020/10/29 15:48
加载中...