Pascal程序

Pascal程序,第1张

依次读入10个数,不需要用数组存下来,每次读入一个数,就让它与min和max比较,如果符合条件就更新min和max

program ttdd8;

var i,x,max,min:longint;

begin

min:=maxlongint; max:=-maxlongint div 2;{赋初值,这一点很重要,一般最大值要赋成一个很小的数,最小值要赋成一个很大的数,这样才能保证能够正确选出最大值和最小值}

for i:=1 to 10 do

begin

read(x);

if x>max then max:=x;

if x<min then min:=x;

end;

writeln('MAX=',max,';MIN=',min);

end

var

i,j:longint;

a:array[13] of char;

temp:char;

begin

read(a[1],a[2],a[3]);

for i:=1 to 2 do

for j:=i+1 to 3 do

if(a[i]>a[j]) then begin

temp:=a[i];

a[i]:=a[j];

a[j]:=temp;

end;

for i:=1 to 3 do

write(a[i]);

end

没用编译器,如果有小错误多多包容,希望能够帮上忙

1)

program ss;

var a:array [14] of integer;b,c,d,e:integer;

begin

for b:=1 to 4 do

read(a[b]);

for c:= 1 to 3 do

begin

for d:=c+1 to 4 do

if a[c]<a[d] then

begin

e:=a[c];a[c]:=a[d];a[d]:=e;

end;

end;

write(a[b]);

end

第二个只要用if 和then 就行了,

我也是新手,所以有错误请多多包涵。

var pan:array[016,016] of string;

i,j,h1,h2,l1,l2,h,l,n,n1,n2,choose,z1,z2:integer;

ju1,ju2:array[010000] of string;

s1,s2,p1,p2:string;

hui1,hui2:boolean;

procedure juout;

begin

for i:=1 to z1 do

writeln(ju1[i],ju2[i]);

writeln('1 保存棋局');

writeln('2 退出');

read(choose);

case choose of

1:begin

assign(output,'五子棋棋局txt');

rewrite(output);

for i:=1 to z1 do

writeln(ju1[i],ju2[i]);

close(output);

exit;

end;

2:exit;

end;

end;

procedure options;

begin

writeln('双方悔棋次数限定:');

writeln('(初始值为0)');

read(n);

n1:=n;

n2:=n;

end;

procedure out;

begin

write(' ');

for i:=1 to 15 do

write(i:2);

writeln;

for i:=1 to 15 do

begin

write(i:2);

for j:=1 to 15 do

write(pan[i,j]);

writeln;

end;

end;

function trytry1(h,l:integer):boolean;

var i,t:integer;

begin

trytry1:=false;

t:=0;

i:=0;

while pan[h-i,l]='○' do begin inc(i); inc(t); end;

i:=0;

while pan[h+i,l]='○' do begin inc(i); inc(t); end;

if t>=6 then begin trytry1:=true; exit; end;

t:=0;

i:=0;

while pan[h,l-i]='○' do begin inc(i); inc(t); end;

i:=0;

while pan[h,l+i]='○' do begin inc(i); inc(t); end;

if t>=6 then begin trytry1:=true; exit; end;

t:=0;

i:=0;

while pan[h-i,l-i]='○' do begin inc(i); inc(t); end;

i:=0;

while pan[h+i,l+i]='○' do begin inc(i); inc(t); end;

if t>=6 then begin trytry1:=true; exit; end;

t:=0;

i:=0;

while pan[h-i,l+i]='○' do begin inc(i); inc(t); end;

i:=0;

while pan[h+i,l-i]='○' do begin inc(i); inc(t); end;

if t>=6 then begin trytry1:=true; exit; end;

end;

function trytry2(h,l:integer):boolean;

var i,t:integer;

begin

trytry2:=false;

t:=0;

i:=0;

while pan[h-i,l]='●' do begin inc(i); inc(t); end;

i:=0;

while pan[h+i,l]='●' do begin inc(i); inc(t); end;

if t>=6 then begin trytry2:=true; exit; end;

t:=0;

i:=0;

while pan[h,l-i]='●' do begin inc(i); inc(t); end;

i:=0;

while pan[h,l+i]='●' do begin inc(i); inc(t); end;

if t>=6 then begin trytry2:=true; exit; end;

t:=0;

i:=0;

while pan[h-i,l-i]='●' do begin inc(i); inc(t); end;

i:=0;

while pan[h+i,l+i]='●' do begin inc(i); inc(t); end;

if t>=6 then begin trytry2:=true; exit; end;

t:=0;

i:=0;

while pan[h-i,l+i]='●' do begin inc(i); inc(t); end;

i:=0;

while pan[h+i,l-i]='●' do begin inc(i); inc(t); end;

if t>=6 then begin trytry2:=true; exit; end;

end;

procedure game;

begin

repeat

inc(z1);

writeln('黑棋走子 请输入落子坐标');

read(h,l);

while (h=0) and(l=0) and(hui1=false) do

begin

writeln('对不起,双方不能连续悔棋');

read(h1,l1);

h:=h1;l:=l1;

while (pan[h1,l1]='○') or (pan[h1,l1]='●') or (h1<1) or (h1>15) or(l1<1) or (l1>15) do

begin

writeln('对不起 该处不能落子');

writeln('黑棋走子 请输入落子坐标');

read(h1,l1);

h:=h1;l:=l1;

end;

end;

while (h=0) and(l=0) and(n1=0) do

begin

writeln('对不起,您的悔棋机会已用完');

writeln('黑棋走子 请输入落子坐标');

readln(h,l);

while (pan[h,l]='○')or(pan[h,l]='●')or((h=0) and (l<>0))or((l=0) and (h<>0))or(h1<0)or(h1>15)or(l1<0)or(l1>15) do

begin

writeln('对不起 该处不能落子');

writeln('黑棋走子 请输入落子坐标');

read(h,l);

end;

end;

if (h<>0)and(l<>0) then begin h1:=h; l1:=l; end;

while (pan[h,l]='○')or(pan[h,l]='●')or((h=0) and (l<>0))or((l=0) and (h<>0))or(h1<0)or(h1>15)or(l1<0)or(l1>15) do

begin

writeln('对不起 该处不能落子');

writeln('黑棋走子 请输入落子坐标');

read(h,l);

if (h<>0)and(l<>0) then begin h1:=h; l1:=l; end;

end;

if (h<>0) and(l<>0) then

begin

s1:=pan[h1,l1];

pan[h1,l1]:='○';

hui2:=true;

str(h1,p1);str(l1,p2);

ju1[z1]:='黑棋在'+p1+','+p2+'落子 ';

out;

end;

while (h=0) and (l=0) do

begin

pan[h1,l1]:=s1;

pan[h2,l2]:=s2;

out;

writeln('黑棋悔棋');

writeln('黑棋走子 请输入落子坐标');

hui2:=false;

dec(n1);

dec(z1);

dec(z2);

ju2[z2]:='';

ju1[z1]:='';

writeln('还可悔棋',n1,'次');

read(h1,l1);

h:=h1;

l:=l1;

while (pan[h1,l1]='○') or (pan[h1,l1]='●') or (h1<1) or (h1>15) or(l1<1) or (l1>15) do

begin

writeln('对不起 该处不能落子');

writeln('黑棋走子 请输入落子坐标');

read(h1,l1);

end;

s1:=pan[h1,l1];

pan[h1,l1]:='○';

hui2:=false;

str(h1,p1);str(l1,p2);

ju1[z1]:='黑棋在'+p1+','+p2+'落子 ';

out;

end;

if trytry1(h1,l1)=true then begin writeln('黑棋胜'); readln; juout; break; end;

inc(z2);

writeln('白棋走子 请输入落子坐标');

read(h,l);

while (h=0) and(l=0) and(hui2=false) do

begin

writeln('对不起,双方不能连续悔棋');

read(h2,l2); h:=h2;l:=l2;

while (pan[h2,l2]='○') or (pan[h2,l2]='●') or (h2<1) or (h2>15) or(l2<1) or (l2>15) do

begin

writeln('对不起 该处不能落子');

writeln('白棋走子 请输入落子坐标');

read(h2,l2);

h:=h2;l:=l2;

end;

end;

while (h=0) and(l=0) and(n2=0) do

begin

writeln('对不起,您的悔棋机会已用完');

writeln('白棋走子 请输入落子坐标');

readln(h,l);

while (pan[h,l]='○')or(pan[h,l]='●')or((h=0) and (l<>0))or((l=0) and (h<>0))or(h1<0)or(h1>15)or(l1<0)or(l1>15) do

begin

writeln('对不起 该处不能落子');

writeln('白棋走子 请输入落子坐标');

read(h,l);

end;

end;

if (h<>0)and(l<>0) then begin h2:=h; l2:=l; end;

while (pan[h,l]='○')or(pan[h,l]='●')or((h=0) and (l<>0))or((l=0)and (h<>0))or(h2<0)or(h2>15)or(l2<0)or(l2>15) do

begin

writeln('对不起 该处不能落子');

writeln('白棋走子 请输入落子坐标');

read(h,l);

if (h<>0)and(l<>0) then begin h2:=h; l2:=l; end;

end;

if (h<>0) and(l<>0) then

begin

s2:=pan[h2,l2];

pan[h2,l2]:='●';

hui1:=true;

str(h2,p1);str(l2,p2);

ju2[z2]:='白棋在'+p1+','+p2+'落子 ';

out;

end;

while (h=0) and (l=0) do

begin

pan[h1,l1]:=s1;

pan[h2,l2]:=s2;

out;

writeln('白棋悔棋');

writeln('白棋走子 请输入落子坐标');

hui1:=false;

dec(n2);

dec(n1);

ju1[z1]:='';

ju2[z2]:='';

writeln('还可悔棋',n2,'次');

read(h2,l2);

h:=h2;

l:=l2;

while (pan[h2,l2]='○') or (pan[h2,l2]='●') or (h2<1) or (h2>15) or(l2<1) or (l2>15) do

begin

writeln('对不起 该处不能落子');

writeln('白棋走子 请输入落子坐标');

read(h2,l2);

end;

s2:=pan[h2,l2];

str(h2,p1);str(l2,p2);

ju2[z2]:='白棋在'+p1+','+p2+'落子 ';

pan[h2,l2]:='●';

out;

end;

if trytry2(h2,l2)=true then begin writeln('白棋胜'); readln; juout; break; end;

until 1=2;

end;

begin

writeln('欢迎使用Free Pascal游戏程序');

readln;

writeln('作者:王子成 ');

readln;

writeln('翻版必究');

readln;

writeln;

writeln('游戏——五子棋');

readln;

n1:=0;

n2:=0;

while choose<>1 do

begin

writeln('1 开始游戏');

writeln('2 游戏说明');

writeln('3 设置');

writeln('4 退出');

readln(choose);

case choose of

1:;

2:begin

writeln('本游戏规则与传统五子棋规则相同,落子时需输入落子的行列;悔棋需在己方回合内输入“0 0”即可,双方不可连续悔棋');

readln;

end;

3:begin options; readln; end;

4:exit;

end;

end;

z1:=0;

z2:=0;

hui1:=false;

hui2:=false;

for i:=2 to 14 do

for j:=2 to 14 do

pan[i,j]:='╋';

for i:=1 to 15 do

begin

pan[1,i]:='┳';

pan[i,1]:='┣';

pan[15,i]:='┻';

pan[i,15]:='┫';

end;

pan[1,1]:='┏';

pan[1,15]:='┓';

pan[15,1]:='┗';

pan[15,15]:='┛';

out;

readln;

writeln('////游戏开始\\\\');

game;

readln;

readln;

end

楼上的是穷举算法,要O(n^2)的时间。

我的是DP,只用O(n)的时间,比他快了n倍。

var

x,y,tmp,now,i:longint;

ax,ay,ans:longint;

begin

ax:=0;

ay:=0;

ans:=0;

now:=0;

x:=0;

y:=0;

i:=0;

while not eoln do begin

read(tmp);

inc(i);

now:=now+tmp;

if now<tmp then begin

now:=tmp;

x:=i;

end;

y:=i;

if now>ans then begin

ans:=now;

ax:=x;

ay:=y;

end;

end;

readln;

writeln('max=',ans);

writeln('From No',ax,' to No',ay);

end

以上就是关于Pascal程序全部的内容,包括:Pascal程序、pascal程序、求Pascal程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zz/9345490.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存