首页 热点专区 义务教育 高等教育 出国留学 考研考公

Pascal回文猜想

发布网友 发布时间:2022-04-22 01:17

我来回答

2个回答

热心网友 时间:2023-09-18 08:11

var
n1:string;
a,b,c:array [1..254] of byte;
h,i,j,k:integer;

procere s_add;
var m,n:integer;
begin
k:=h; {记录原数据长度}
for m:=1 to h do begin
a[m]:=c[m];
b[m]:=c[h-m+1];
end;
n:=0;
for m:=1 to h do begin
c[m]:=a[m]+b[m]+n;
n:=c[m] div 10;
c[m]:=c[m] mod 10;
end;
if n>0 then begin
inc(h); { 数据长度增一位}
c[h]:=n;
end;
end;

procere s_write;
var m:integer;
begin
write('(',j,') ');
for m:=1 to k do write(a[m]);
write('+');
for m:=1 to k do write(b[m]);
write('=');
for m:=h downto 1 do write(c[m]);
writeln;
end;

function f_Palindrome:boolean;
var m:integer; b:boolean;
begin
b:=true;
for m:=1 to h div 2 do
if c[m]<>c[h-m+1] then begin
b:=false;
break;
end;
f_Palindrome:=b;
end;

begin
write('input number:');
readln(n1);
h:=length(n1);
for i:=1 to h do c[i]:=ord(n1[i])-48;
j:=0;
repeat
inc(j);
s_add;
s_write;
if f_Palindrome then break;
until false;
readln;
end.

热心网友 时间:2023-09-18 08:12

var
i,tot:longint;
a,b,c:array[0..225] of longint;
n1:string;
function che(s:string):boolean;
begin
che:=false;
for i:=1 to length(s) do
if s[i] <> s[length(s)-i+1] then
exit(true);
end;
function jia:string;
begin
a[0]:=length(n1);
b[0]:=length(n1);
c[0]:=length(n1); c[c[0]+1]:=0;
for i:=1 to a[0] do begin
a[i]:=ord(n1[i])-48;
b[i]:=ord(n1[length(n1)-i+1])-48;
c[i]:=a[i]+b[i];
end;
for i:=1 to c[0] do begin
c[i+1]:=c[i+1]+c[i] div 10;
c[i]:=c[i] mod 10;
end;
if c[c[0]+1] > 0 then c[0]:=c[0]+1;
write(n1,'+');for i:=a[0] downto 1 do write(n1[i]);
jia:=''; for i:=1 to c[0] do jia:=chr(c[i]+48)+jia;
writeln('=',jia); tot:=tot+1;
end;
begin
readln(n1); tot:=0;
while che(n1) do
n1:=jia;
writeln('total=',tot);
end.

---------
Running ":\fp2.0.4\bin\i386-win32\aa.exe "
1992
1992+2991=4983
4983+34=8877
8877+7788=16665
16665+56661=73326
73326+62337=135663
135663+366531=502194
502194+491205=993399
total=7

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com