1.Link:

http://poj.org/problem?id=2602

http://bailian.openjudge.cn/practice/2602/

2.Content:

Superlong sums
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 22337   Accepted: 6577

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

4
0 4
4 2
6 8
3 7

Sample Output

4750

Hint

Huge input,scanf is recommended.

Source

3.Method:

大数加法,直接套模板

http://www.cnblogs.com/mobileliker/p/3512632.html

4.Code:

#include <string>
#include <cstdio>
#include <iostream> using namespace std; string sum(string s1,string s2)
{
if(s1.length()<s2.length())
{
string temp=s1;
s1=s2;
s2=temp;
}
int i,j;
for(i=s1.length()-,j=s2.length()-;i>=;i--,j--)
{
s1[i]=char(s1[i]+(j>=?s2[j]-'':)); //注意细节
if(s1[i]-''>=)
{
s1[i]=char((s1[i]-'')%+'');
if(i) s1[i-]++;
else s1=''+s1;
}
}
return s1;
} int main()
{
//freopen("D://input.txt","r",stdin); int i; int n;
scanf("%d\n",&n); string str1(n,'\0');
string str2(n,'\0'); for(i = ; i < n; ++i) scanf("%c %c\n",&str1[i],&str2[i]); //for(i = 0; i < n; ++i) printf("%c",str1[i]);
//printf("\n");
//for(i = 0; i < n; ++i) printf("%c",str2[i]);
//printf("\n"); string res = sum(str1,str2); if(res.size() < n)
{
i = n - res.size();
while(i--) cout << "";
}
cout << res << endl; return ;
}

5.Reference:

Poj OpenJudge 百练 2602 Superlong sums的更多相关文章

  1. Poj OpenJudge 百练 1860 Currency Exchang

    1.Link: http://poj.org/problem?id=1860 http://bailian.openjudge.cn/practice/1860 2.Content: Currency ...

  2. Poj OpenJudge 百练 1062 昂贵的聘礼

    1.Link: http://poj.org/problem?id=1062 http://bailian.openjudge.cn/practice/1062/ 2.Content: 昂贵的聘礼 T ...

  3. Poj OpenJudge 百练 2389 Bull Math

    1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...

  4. Poj OpenJudge 百练 1573 Robot Motion

    1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...

  5. Poj OpenJudge 百练 2632 Crashing Robots

    1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...

  6. Poj OpenJudge 百练 Bailian 1008 Maya Calendar

    1.Link: http://poj.org/problem?id=1008 http://bailian.openjudge.cn/practice/1008/ 2.content: Maya Ca ...

  7. Poj 2602 Superlong sums(大数相加)

    一.Description The creators of a new programming language D++ have found out that whatever limit for ...

  8. Openjudge 百练第4109题

    在OpenJudge看到一个题目(#4109),题目描述如下: 小明和小红去参加party.会场中总共有n个人,这些人中有的是朋友关系,有的则相互不认识.朋友关系是相互的,即如果A是B的朋友,那么B也 ...

  9. [OpenJudge] 百练2754 八皇后

    八皇后 Description 会下国际象棋的人都很清楚:皇后可以在横.竖.斜线上不限步数地吃掉其他棋子.如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. ...

随机推荐

  1. phonegap 安装和使用eclipse

    1.下载nodejs...然后注销让nodejs可用 2.下载jdk,ant.和安卓的sdk. jdk是为ant编译时需要,设置JAVA_HOME环境变量 C:\Program Files\Java\ ...

  2. jsonp跨域原理解析

    前言: 跨域请求是前台开发中经常遇到的场景,但是由于浏览器同源策略,导致A域下普通的http请求没法加载B域下的数据,跨域问题由此产生.但是通过script标签的方式却可以加载非同域下的js,因此可以 ...

  3. Anaconda packages list

    # packages in environment at D:\Applications\Anaconda3:#alabaster 0.7.6 py35_0 anaconda 2.4.0 np110p ...

  4. Python学习 之 走进python

    1.Python:是一种解释型的.面向对象的.带有动态语义的高级程序设计语言. 2.Python发展阶段 —CNRI时期 —BeOpen时期 —DC时期 —Python 3.0 Python里程碑:2 ...

  5. 小白日记25:kali渗透测试之提权(五)--利用配置不当提权

    利用配置不当提权 与漏洞提权相比,更常见的方法.在大部分企业环境下,会有相应的补丁更新策略,因此难以通过相应漏洞进行入侵.当入侵一台服务器后,无法照当相应的补丁进行提权,可通过寻找是否存在配置不当进行 ...

  6. [未完成]关于DOM的总结

    这样有什么好处吗? 一但这些东西变成了节点对象,意味着每一个节点对象都会有很多属性和行为提供出来. 如果div是一个对象,那么就可以针对这个对象调用其中的一些方法,对div操作. 这个操作可以包括,比 ...

  7. poj 2057 树形dp 贪心

    思路:设sum[i],le[i],back[i],worm[i]分别表示以i为根节点需要的完成步数,叶子节点数,失败回退步数,以及i是否有虫. #include<iostream> #in ...

  8. js验证 button 提交

    <form class="form-horizontal" role="form" action="member_add" metho ...

  9. ubuntu共享文件夹给virtualbox

    在ubuntu或者linuxmint等linux系统下安装了virtualbox,可以通过共享文件夹的方式,把文件夹共享给virtualbox下的虚拟机系统,我这里的虚拟机系统是win7,共享过程如下 ...

  10. 基本STRUTS标签-学习笔记-Logic标签

    BEAN标签(name 是从别处得来的:id是自己的,相当于变量:property相当于变量的值) 前提: String str=request.getParameter("param&qu ...