Poj OpenJudge 百练 2602 Superlong sums
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 7Sample Output
4750Hint
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的更多相关文章
- Poj OpenJudge 百练 1860 Currency Exchang
1.Link: http://poj.org/problem?id=1860 http://bailian.openjudge.cn/practice/1860 2.Content: Currency ...
- Poj OpenJudge 百练 1062 昂贵的聘礼
1.Link: http://poj.org/problem?id=1062 http://bailian.openjudge.cn/practice/1062/ 2.Content: 昂贵的聘礼 T ...
- Poj OpenJudge 百练 2389 Bull Math
1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...
- Poj OpenJudge 百练 1573 Robot Motion
1.Link: http://poj.org/problem?id=1573 http://bailian.openjudge.cn/practice/1573/ 2.Content: Robot M ...
- Poj OpenJudge 百练 2632 Crashing Robots
1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...
- Poj OpenJudge 百练 Bailian 1008 Maya Calendar
1.Link: http://poj.org/problem?id=1008 http://bailian.openjudge.cn/practice/1008/ 2.content: Maya Ca ...
- Poj 2602 Superlong sums(大数相加)
一.Description The creators of a new programming language D++ have found out that whatever limit for ...
- Openjudge 百练第4109题
在OpenJudge看到一个题目(#4109),题目描述如下: 小明和小红去参加party.会场中总共有n个人,这些人中有的是朋友关系,有的则相互不认识.朋友关系是相互的,即如果A是B的朋友,那么B也 ...
- [OpenJudge] 百练2754 八皇后
八皇后 Description 会下国际象棋的人都很清楚:皇后可以在横.竖.斜线上不限步数地吃掉其他棋子.如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. ...
随机推荐
- F5 负载均衡
http://xjsunjie.blog.51cto.com/blog/999372/697285 http://www.eimhe.com/thread-142659-1-1.html
- 初探Linux进程管理机制
转至:http://ixdba.blog.51cto.com/2895551/543737 一 .进程的概念和分类1.进程的概念 Linux是一个多用户多任务的操作系统.多用户是指多个用户可以在同一时 ...
- KMeans聚类 K值以及初始类簇中心点的选取 转
本文主要基于Anand Rajaraman和Jeffrey David Ullman合著,王斌翻译的<大数据-互联网大规模数据挖掘与分布式处理>一书. KMeans算法是最常用的聚类算法, ...
- Sequence用堆排序
Description Given m sequences, each contains n non-negative integer. Now we may select one number fr ...
- ReactNative 大图手势浏览技术分析
支持通用的手势缩放,手势跟随,多图翻页 手势系统 通过 PanResponder.create 创建手势响应者,分别在 onPanResponderMove 与 onPanResponderRelea ...
- 关于Servlet会话跟踪的那些事儿
关于servlet会话跟踪,一搜都能搜出很多.我也不免落入俗套,也总结了一把.希望我所总结的知识尽量是知识海洋里的一汪清泉.能帮助到我自己和哪怕一个人,那也是值得的. 故事由来: 我们知道,http协 ...
- uva 784 Maze Exploration 染色 搜索水题 DFS
染色问题,其实就是看看图上某一点能扩散多少. 用DFS解决,因为BFS不是很熟 =-=...以后要多练. 提交后32ms,优化了一下,在递归前进行判定,优化到22ms,不是优化的很好... 代码: # ...
- html 动态添加TABLE的行。
<script type="text/javascript"> var pos =4;//默认位置为4,根据自己需要,也可以通过鼠标事件获取当前行数. function ...
- SQL Server 2012 performance dashboard 安装
微软提供了一个很好用的工具performance dashboard: 下载地址: http://www.microsoft.com/en-us/download/details.aspx?id=29 ...
- 关于使用vss版本管理工具中的sln,suo文件作用
Visual Studio.NET采用两种文件类型(.sln和.suo)来存储特定于解决方案的设置,它们总称为解决方案文件.为解决方案资源管理器提供显示管理文件的图形接口所需的信息 从而在每次继续开发 ...