用pascal编程

2024-11-22 00:14:47
推荐回答(5个)
回答(1):

我用了不少时间做这么多题 多给点分吧~

、(附加题)输入一串字符,以“?”结束输出其中小写字母个数与数字个数。
program ex;
var
ch:char;
t,t1:integer;
begin
t:=0;t1:=0;
read(ch);
while ch<>'?' do begin
if (ord(ch)>=97)and(ord(ch)<=122) then t:=t+1;
if (ord(ch)>=48)and(ord(ch)<=57) then t1:=t1+1;
read(ch);
end;
writeln;
writeln(t,' ',t1);
end.

编程求下式中n的最大值:2×2+4×4+6×6+...+n×n<1500。
program ex1;
var s,n:integer;
begin
n:=2;
s:=0;
while s<1500 do
begin
s:=s+n*n;
n:=n+2;
end;
writeln(n);
readln
end.

打印下列图案:
*
* * *
* * * * *
program ex2;
var i,j,n:integer;
begin
readln(n);
for j:=1 to n do
if n mod 2<>0 then
for i:=1 to j do
begin
write('*');
if j=i then writeln;
end;
end.

打印下列图案
# @ *
# # @ @ * *
# # # @ @ @ * * *
program ex3;
var i,j,n:integer;
begin
readln(n);
i:=1;
while i<=n do
begin
for j:=1 to i do write('#');
for j:=1 to i do write('@');
for j:=1 to i do write('*');
writeln;
i:=i+1;
end;
end.

试编程找出能被各位数字之和整除的一切两位数。
program ex4;
var i,j,s,k:integer;
begin
for i:=10 to 99 do
begin
j:=i div 10;
k:=i mod 10;
s:=j+k;
if i mod s=0 then write(i,' ');
end;
readln
end.

一个自然数是素数,且它的数字位置经过任意对换后仍为素数,则称为绝对素数,例如13。试找出所有两位数的绝对素数。
program ex5;
var n,i,j:integer;
function sz(a:integer):boolean;
var k,s:integer;
begin
s:=0;
for k:=2 to a-1 do
if a mod k=0 then s:=s+1;
if s=0 then sz:=true else sz:=false;
end;
begin
for i:=10 to 99 do
begin
j:=i div 10;
n:=i mod 10;
n:=10*n+j;
if sz(i) and sz(n) then write(i,' ');
end;
readln
end.

输入一个奇数,输出下列图形;
输入:3
*
***
*
输入:5
*
***
*****
***
*
输入一个奇数,输出下列图形;
输入:3
*
***
*
输入:5
*
***
*****
***
*
输入一个奇数,输出下列图形;
输入:3
*
***
*
输入:5
*
***
*****
***
*
program ex6;
var i,n,j:integer;
begin
readln(n);
for i:=1 to n do
if i mod 2<>0 then
for j:=1 to i do
begin
write('*');
if j=i then writeln
end;

for i:=n-1 downto 1 do
if i mod 2<>0 then
for j:=1 to i do
begin
write('*');
if j=i then writeln
end;
readln
end.

打印下列图形:
1
121
12321
1234321
12321
121
1
program ex7;
var i:integer;

procedure draw(a:integer);
var n:integer;
begin
for n:=1 to a do write(n);
for n:=a-1 downto 1 do write(n);
writeln;
end;

begin
for i:=1 to 4 do draw(i);
for i:=3 downto 1 do draw(i);
readln
end.

回答(2):

附加题:
var
s,i:char;
a:array['a'..'z']of integer;
b:array['0'..'9']of integer;
begin
for i:='a' to 'z' do a[i]:=0;
{将每个字母计数器清零,当然如果读入是没有这个字母那还是0}
repeat
read(s);
if (s>='a')and(s<='z') then a[s]:=a[s]+1;
if (s>='0')and(s<='9') then b[s]:=b[s]+1;
{读入并计算每个字母或数字出现次数}
until s='?';
for i:='a' to 'z' do begin write(i,':'); write(a[i],' '); end;
writeln;
writeln;
for i:='0' to '9' do begin write(i,':'); write(b[i]); end;
{输出}
end.
都对,可以看懂吧!O(∩_∩)O哈哈~ 其他题太多了。
网上都可以查到,都是些经典的题。
要加分哦O(∩_∩)O!!

回答(3):

var
s,i:char;
a:array['a'..'z']of integer;
b:array['0'..'9']of integer;
begin
for i:='a' to 'z' do a[i]:=0;

回答(4):

var
a,b:string;
function
get_post(a,b:string):string;
var

al,ar,bl,br,t:string;

mid:integer;
begin

if
(a='')
or
(b='')
then

get_post:=a+b

else
begin

mid:=pos(b[1],
a);

if
mid=0
then

get_post:='error'

else
begin

al:=copy(a,1,mid-1);

ar:=copy(a,mid+1,
length(a)-mid);

bl:=copy(b,2,mid-1);

br:=copy(b,mid+1,length(b)-mid);

get_post:=get_post(al,
bl)+get_post(ar,
br)+b[1];

end;

end;
end;
begin

readln(a);

readln(b);

writeln(get_post(a,b));
end.

回答(5):

附加题:
program ex;
var
ch:char;
t,t1:integer;
begin
t:=0;t1:=0;
read(ch);
while ch<>'?' do begin
if (ord(ch)>=97)and(ord(ch)<=122) then t:=t+1;
if (ord(ch)>=48)and(ord(ch)<=57) then t1:=t1+1;
read(ch);
end;
writeln;
writeln(t,' ',t1);
end.