sums
来源:互联网 发布:mac驱动下载 编辑:程序博客网 时间:2024/05/16 06:31
Description
Sometimes Ziwen need to operate even larger numbers. A limit of 1000 digits is so small… You have to find the sum of two numbers with maximal size of 1 000 000 digits.
Input
The first line contains a single integer N that is the length of the given integers(1 ≤ N ≤ 1 000 000). It is followed by these integers written in columns. That is, the next N lines contain two digits each, divided by a space. Each of the two given integers is not less than 0, and the length of their sum does not exceed N. The integers may contain leading zeroes.
Output
Output exactly N digits in a single line representing the sum of these two integers.
Sample Input
40 44 26 83 7
Sample Output
4750
代码
#include<iostream>using namespace std;main(){ int n; while(scanf("%d",&n)!=EOF){ int a[n][2]; for(int i=0;i<n;i++){ scanf("%d%d",&a[i][0],&a[i][1]); } int c[n+1]; for(int i=0;i<n+1;i++){ c[i]=0; } static int k=0; for(int i=n-1;i>=0;i--){ c[i+1]=(a[i][0]+a[i][1]+k)%10; k=(a[i][0]+a[i][1]+k)/10; } if(c[0]!=0) printf("%d",c[0]); for(int i=1;i<n+1;i++){ printf("%d",c[i]); } }}
算法还是较简单的,不过在开始测试,发现输出的总是00000X,后面才发现少了using namespace std; 但程序可以运行,不过无法的出正确的结果,原因待究。
0 0
- Sums
- sums
- 2Sums&3Sums
- Sums of Sums
- Alternating Sums
- Subset Sums
- Subset Sums
- Herd Sums
- Triangular Sums
- Subset Sums
- Triangular Sums
- Triangular Sums
- Subset Sums
- Triangular Sums
- 3 sums
- Herd Sums
- Triangular Sums
- NYOJ122Triangular Sums
- java+oracle+web(第七天) tomcat介绍 (四)实现https://www.igo.com 直接访问我的主页
- js 生成随机数方法
- 常用算法之排序算法四【归并排序】
- 机器学习实战 朴素贝叶斯
- 二叉平衡树
- sums
- 使用viewport的元数据、CSS和Javascript来为不同分辨率的屏幕设置合适的页面
- udp服务端和客户端程序设计
- MFC 文件保存对话框的设置的那些秘密
- Android开发技巧——实现底部图标文字的导航栏(已更新)
- Spring <context:annotation-config/> 解说
- 逆序替换空格 -- 剑指offer
- 【c++总结-类】一个例子知道类的创建,对象,函数实现,构造函数,析构函数
- hdu1850尼姆博弈