pascal题目现在给你N个0~9的数字并排成一列,同时还给出了一个取数长度L.
最佳回答
//By 灰天飞雁 htfy96@qq。com 转载请保留此行
{
TestData:
Input:
12
6 6 5 3 6 5 3 1 6 1 4 1
3
Output:
653
}
Var
a:array[0。。1000] of byte; //存储n个数字
t:array[0。。1000] of qword; //存储取出的n-l+1个数中是质数的
n,i,l,top,j:longint;
now,w,y:qword;
Function iszhi(P:qword):boolean;inline;//判断一个数是否为质数
var
i:longint;
begin
for i:=2 to trunc(sqrt(p)) do
if p mod i=0 then exit(false);
exit(true);
end;
procedure check(P:qword);inline; //检查一个数是否为质数,若是则将其加入T中
begin
if iszhi(P) then
begin
inc(top);
t[top]:=p;
end;
end;
begin
top:=0; //top:T数组的栈顶
readln(n);
for i:=1 to n do
read(a[i]);
readln;
readln(l);
now:=0;//now 存储的是当前处理的长度为l的数
w:=1; //w代表当前处理那一位的权值
for i:=l downto 1 do
begin
now:=now+a[i]*w;
w:=w*10;
end; //这一部分是计算第1~L位的那个数字的
w:=w div 10; //最高位的权值在最后多乘了一个10
check(now); //检查第一个数
for i:=l+1 to n do //i代表了当前处理数的最后一位。当前处理数=前一个数除掉首位(mod w) *10 +当前这一位的数字(+a[i])
begin
now:=now mod w;
now:=now*10+a[i];
check(now);
end;
for i:=1 to top-1 do//数据不多就冒泡了……
for j:=i+1 to top do
if t[i]>t[j] then
begin
y:=t[i];
t[i]:=t[j];
t[j]:=y;
end;
for i:=1 to top do
if (t[i]<>t[i-1]) or (i=1) then //去重
writeln(t[i]);
readln
end。
最新回答共有2条回答
-
2026-03-31 19:40:17痴情的乐曲
回复program number;//By 灰天飞雁 htfy96@qq。com 转载请保留此行{TestData:Input:126 6 5 3 6 5 3 1 6 1 4 13Output:653}Var a:array[0。。1000] of byte; //存储n个数字 t:array[0。。1000] of qword; //存储取出的n-l+1个数中是质数的 n,i,l,top,j:longint; now,w,y:qword;Function iszhi(P:qword):boolean;inline;//判断一个数是否为质数var i:longint; begin for i:=2 to trunc(sqrt(p)) do if p mod i=0 then exit(false); exit(true);end;procedure check(P:qword);inline; //检查一个数是否为质数,若是则将其加入T中 begin if iszhi(P) then begin inc(top); t[top]:=p; end;end; begin top:=0; //top:T数组的栈顶 readln(n); for i:=1 to n do read(a[i]); readln; readln(l); now:=0;//now 存储的是当前处理的长度为l的数 w:=1; //w代表当前处理那一位的权值 for i:=l downto 1 do begin now:=now+a[i]*w; w:=w*10; end; //这一部分是计算第1~L位的那个数字的 w:=w div 10; //最高位的权值在最后多乘了一个10 check(now); //检查第一个数 for i:=l+1 to n do //i代表了当前处理数的最后一位。当前处理数=前一个数除掉首位(mod w) *10 +当前这一位的数字(+a[i]) begin now:=now mod w; now:=now*10+a[i]; check(now); end; for i:=1 to top-1 do//数据不多就冒泡了…… for j:=i+1 to top do if t[i]>t[j] then begin y:=t[i]; t[i]:=t[j]; t[j]:=y; end; for i:=1 to top do if (t[i]<>t[i-1]) or (i=1) then //去重 writeln(t[i]); readlnend。
热门文章
- 康达学院专转本五年制
- 高考一个考场分ab卷吗
- not only but also用法
- 某物体做自由落体运动,从释放开始计时,则物体在前2s内的平均速度为______m/s,物体下落2m时的速度大小为______m/s.
- 三角函数公式大全表格
- 地理中考必背知识点2022
- 2013-2014学年小学六年级科学上学期期末考试试卷及答案
- 人教版2014-2015学年小学五年级英语第二学期期中教学质量检测试卷及答案
- 【Linux驱动开发】设备树详解(二)设备树语法详解
- 别跟客户扯细节
- 在别的城市买房子能落户吗
- 卖房前要把装修贷还完吗
- 高中政治教学提高教学效果的方法探究
- “互联网+”背景下的初中英语课堂教学改革与创新策略研究
- 2022年终止合同范本
- 租房合同范本范文
- 如何挑选土豆
- 如何挑选土鸡
