- 2
- 0
- 约5.02万字
- 约 50页
- 2018-04-14 发布于浙江
- 举报
[2018年最新整理]信息学联赛算法关于算法的资料
一、高精度乘法
1.高精度乘单精度(1位数)
程序如下:
program HighPrecision3_Multiply1;
const
maxlen=100; { max length of the number }
type
hp=record
len:integer; { length of the number }
s:array[1..maxlen] of integer;
end;
var
x,y:hp; { x:input hp ; y:output }
z:integer; { z:input lp }
procedure PrintHP(const p:hp);
var i:integer;
begin
for i:=p.len downto 1 do write(p.s[i]);
end;
procedure init;
var
st:string;
i:integer;
begin
readln(st);
x.len:=length(st);
for i:=1 to x.len do { change string to HP }
x.s[i]:=ord(st[x.len+1-i])-ord(0);
readln(z);
end;
procedure Multiply(a:hp;b:integer;var c:hp); { c:=a*b }
var i,len:integer;
begin
fillchar(c,sizeof(c),0);
len:=a.len;
for i:=1 to len do
begin
inc(c.s[i],a.s[i]*b);
inc(c.s[i+1],c.s[i] div 10);
c.s[i]:=c.s[i] mod 10;
end;
inc(len);
while(c.s[len]=10) do
begin
inc(c.s[len+1],c.s[len] div 10);
c.s[len]=c.s[len] mod 10;
inc(len);
end;
while(len1) and (c.s[len]=0) do dec(len);
c.len:=len;
end;
procedure main;
begin
Multiply(x,z,y);
end;
procedure out;
begin
PrintHP(y);
writeln;
end;
begin
init;
main;
out;
end.
2.高精度乘一个整型数据(integer)
只需要将上述程序的hp类型定义如下即可:
type
hp=record
len:integer { length of the number }
s:array[1..maxlen] of longint
{ s[1] is the lowest position
s[len] is the highest position }
end;
3.高精度乘高精度
程序如下:
program HighPrecision4_Multiply2;
const
maxlen=100; { max length of the number }
type
hp=record
len:integer; { length of the number }
s:array[1..maxlen] of integer
end;
var
x:array[1..2] of hp;
y:hp; { x:input ; y:output }
procedure PrintHP(const p:hp);
var i:integer;
begin
for i:=p.len downto 1 do write(p.s[i]);
end;
procedure init;
var
st:string;
j,i:integer;
begin
for j:=1 to 2 do
begin
readln(st);
x[j].le
您可能关注的文档
- [2018年最新整理]保险公司怎样才能不亏本1.ppt
- [2018年最新整理]保险公司资产配置的结构变迁与国际比较.doc
- [2018年最新整理]保险合同的履行.ppt
- [2018年最新整理]保险学(导论).ppt
- [2018年最新整理]保险学CH1保险概述.ppt
- [2018年最新整理]保险学四五六章.ppt
- [2018年最新整理]保险增员:如何寻找我的“对象”.ppt
- [2018年最新整理]保险学概论形成性考核册答案11.doc
- [2018年最新整理]保险学测试练习题.ppt
- [2018年最新整理]保险学课件(华东理工易上力).ppt
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
最近下载
- 产后骨盆修复全流程指导手册.docx VIP
- HG∕T 2568-2021 工业偏硅酸钠.pdf
- 2025年鄂尔多斯市特岗教师招聘考试真题汇编附答案解析.docx VIP
- 24小时客服电话:010-82311666免费咨询热线:4.doc VIP
- 2020ACLS学员课课前测试中文版试题+答案.pdf VIP
- 髌骨脱位康复护理新进展.pptx VIP
- 急救医学-第四章心悸.ppt VIP
- 高中数学必修第四册第十一章综合测试01含答案解析.pdf VIP
- 2022年高考物理核心高频考点专题22 圆周运动的轻绳、轻杆模型(解析版).pdf VIP
- 马工程-中国古代文学史(第二版)上册第三编魏晋文学全套PPT课件50109.pptx
原创力文档

文档评论(0)