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. 实现经常使用的配置文件/初始化文件读取的一个C程序

    在编程中,我们常常会遇到一些配置文件或初始化文件. 这些文件通常后缀名为.ini或者.conf.能够直接用记事本打开.里面会存储一些程序參数,在程序中直接读取使用.比如,计算机与server通信.se ...

  2. oc-04-类的声明和实现

    //main.m //10-[掌握]类的声明和实现 //.h为类的声明,.m为类的实现,+表示类方法静态方法,-表示对象方法..h文件中的方法都是public不能更改的.变量3中访问域:public, ...

  3. .net平台下C#socket通信(转)

    上篇.net平台下C#socket通信(上)介绍了socket通信的基本原理及最基本的通信方式.本文在此基础上就socket通信时经常遇到的问题做一个简单总结,都是项目中的一些小问题,拿来此处便于下次 ...

  4. 使用Areas(区域)分离ASP.NET MVC 项目

    在使用Areas区域时,如果使用默认路由表,将造成路由表冲突,这种情况需要修改一下区域内<区域名称>AreaRegistration.cs和/App_Start/RouteConfig.a ...

  5. 关于MIUI悬浮窗权限问题的解决方案

    先扯会....好久没写Blog了....这段时间有点小忙...瞎忙.....忙的自己都感觉都不应该.....严重影响了生活质量......生活的幸福指数!!!.....到现在还特么的单身!!!求介绍啊 ...

  6. 用Linux安装光盘修复GRUB

    转载:http://lgn21st.iteye.com/blog/179455 需要开视频会议,我不得零时从Ubuntu切换回去百年难道用一次的WinXP...发现自己的XP系统很混乱...决定重新装 ...

  7. Windows 7中使用Eclipse 使用CDT and WinGW 开发C/C++(转载)

    以前使用visual studio 2010编写C/C++,后来接触了Eclipse后,据说eclipse也可以编写C/C++,以前觉得Visual studio 2010还蛮不错的,也没有多大好奇心 ...

  8. poj 3678 2-SAT问题

    思路:将每个点拆分为两个点 a与a' ,a表示为1,a'表示为0.那么条件给的每个边自然就会存在矛盾,然后根据2-SAT建边就行了. #include<iostream> #include ...

  9. Linux系统内核制作和内核模块的基础

    Linux系统内核制作 1.清除原有配置与中间文件 x86:  make distclean arm:  make distclean 2.配置内核 x86:  make menuconfig arm ...

  10. jquery里的宽度详解

    在jQuery中,width()方法用于获得元素宽度:innerWidth()方法用于获得包括内边界(padding)的元素宽度,outerWidth()方法用于获得包括内边界(padding)和边框 ...