poj-2602-Superlong sums
2017-09-29 09:35
447 查看
http://poj.org/problem?id=2602
Superlong sums
Description
The creators of a new programming language D++ have found out that whatever limit for SuperLongInt type they make, sometimes programmers 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 of an input file contains a single number N (1<=N<=1000000) - the length of the integers (in order to make their lengths equal, some leading zeroes can be added). 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 1, and the length of their sum does not exceed N.
Output
Output file should contain exactly N digits in a single line representing the sum of these two integers.
Sample Input
Sample Output
Hint
Huge input,scanf is recommended.
~题意:纵向输入两个数,然后输出相加结果
就是简单高精度加法咯~
Superlong sums
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 23519 | Accepted: 6974 |
The creators of a new programming language D++ have found out that whatever limit for SuperLongInt type they make, sometimes programmers 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 of an input file contains a single number N (1<=N<=1000000) - the length of the integers (in order to make their lengths equal, some leading zeroes can be added). 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 1, and the length of their sum does not exceed N.
Output
Output file should contain exactly N digits in a single line representing the sum of these two integers.
Sample Input
4 0 4 4 2 6 8 3 7
Sample Output
4750
Hint
Huge input,scanf is recommended.
~题意:纵向输入两个数,然后输出相加结果
就是简单高精度加法咯~
#include<iostream> #include<stdio.h> using namespace std; #define maxn 1000005 char a[maxn]; char b[maxn]; char ans[maxn]; int main() { int n; scanf("%d",&n); getchar(); for(int i=1;i<=n;i++) { a[i]=getchar();//字符 getchar();//空格 b[i]=getchar(); getchar(); } int tmp=0; for(int i=n;i>=1;i--) { tmp=tmp+(a[i]-'0')+(b[i]-'0'); ans[i]=(tmp%10+'0'); tmp/=10; } bool flag;//判断最后是否有进位 if(tmp) { ans[0]=(tmp+'0'); flag=true; } else flag=false; if(flag) { for(int i=0;i<=n;i++) { putchar(ans[i]); } } else { for(int i=1;i<=n;i++) { putchar(ans[i]); } } putchar('\n'); }
相关文章推荐
- POJ 2602 Superlong sums
- POJ 2602 Superlong sums (高精度,模拟,水题)
- Poj 2602 Superlong sums(大数相加)
- Poj 2602 Superlong sums(大数相加)
- Poj OpenJudge 百练 2602 Superlong sums
- Poj 2602 Superlong sums(大数相加)
- poj 2602 Superlong sums
- POJ 2602|URAL 1048|Superlong Sums|高精度加法
- ACM篇:POJ2602--Superlong Sums
- POJ 2602 Superlong sums G++
- POJ 2602 Superlong sums
- POJ 2602 Superlong sums(模拟大数加法)
- POJ2602-Superlong sums
- poj 大数 - 2602 Superlong sums
- poj2602 Superlong sums(高精度)
- POJ2602-Superlong sums
- POJ 2602 Superlong sums(高精度)
- POJ 2602 Superlong sums 大整数求和
- POJ2602-Superlong sums
- poj2602——Superlong sums