高精度加法
2016-04-17 21:41
246 查看
做高精度加法其实只要在草稿纸上画一下,模拟一下这个过程就很容易做出来了:
代码:
代码:
var len1,len2,i:longint; a,b,c:array[0..10010] of Longint; s1,s2,s:ansistring; begin readln(s1); readln(s2); if (length(s1)<length(s2)) or ((length(s1)=length(s2)) and (s1<s2)) then begin s:=s1; s1:=s2; s2:=s; end; len1:=length(s1); len2:=length(s2); for i:=1 to len1 do a[len1-i+1]:=ord(s1[i])-48; for i:=1 to len2 do b[len2-i+1]:=ord(s2[i])-48; for i:=1 to len1 do begin c[i]:=c[i]+a[i]+b[i]; c[i+1]:=c[i] div 10; c[i]:=c[i] mod 10; end; inc(len1); while c[len1]=0 do dec(len1); for i:=len1 downto 1 do write(c[i]); writeln; end.
相关文章推荐
- html网页设计
- 网络图 可视化
- nginx+tomcat+memcached实现session共享
- Boosting与Bagging
- 【UNET自学日志】Part5 解决延迟产生的画面不流畅问题
- 学习 Spark Streaming 的重要性
- Android学习(26) -- 数据存储之SQLite数据库的创建
- uva 10154 - Weights and Measures【dp】qi
- 静态代理
- Java数据结构与排序算法——堆和堆排序
- 业务中是否有必要让所有的ViewController统一继承抽象类
- jsp 自定义标签
- 1004 Toxophily
- 周易六十四卦——噬嗑卦
- RecyclerView
- 这恼人的一星期
- 开源后5个月,Google的深度学习都有哪些改变?
- RelativeLayout.addRule()方法
- LeetCode|Two Sum
- 字符串分隔之机试