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个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. ...
随机推荐
- 检测Insert、Capslock、NumLock、ScrollLock状态键的状态
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...
- 构建高效安全的Nginx Web服务器
一 为什么选择Nginx搭建Web服务器 Apache和Nginx是目前使用最火的两种Web服务器,Apache出现比Nginx早.Apache HTTP Server(简称Apache)是世界使用排 ...
- hive-安装0.13.1(hadoop2.2.0)
hadoop2.2.0 hive0.13.1 (事先已经安装好hadoop.MySQL以及在MySQL中建好了hive专用账号,数据创建不创建都可以) 1.下载解压 2.把MySQL驱动加入hive的 ...
- SimpleAliasRegistry implements AliasRegistry
Spring - 4.2.3 // name,alias存储容器 ConcurrentHashMap <alias,name>private final Map<String, St ...
- html笔记03:表单
1.表单是用来收集用户填写的信息,可以说表单就是一个容器,里面的元素的类型可以不一样,所表示的功能也不同. 表单基本语法: <html> <head> <title> ...
- android开发之路09(浅谈SQLite数据库01)
1.SQLite数据库: SQLite 是一个开源的嵌入式关系数据库,实现自包容.零配置.支持事务的SQL数据库引擎. 其特点是高度便携.使 用方便.结构紧凑.高效.可靠. 与其他数据库管理系统不同, ...
- 快餐店运行模拟C++程序源码代写
某快餐店供应若干种快餐和饮料(5种以上),早晨6:00开始营业,晚上11:00打烊.前一天已经安排了若干工人上班,快餐店的用餐位是固定的,每种食物的成本和销售价格是确定的,每种食物的总量是确定的,储存 ...
- SQL Server 调优:set statistics profile on
进行set statistics profile on 设置后 将会返回执行计划表,通过该表,可以理解语句执行的过程,了解SQL Server是否选择了正确的执行计划,进而确定调优方向! 1.返回表字 ...
- linux开机启动配置
vim /etc/rc.d/rc.local 把命令写在这里
- [改善Java代码]自由选择字符串拼接方法
对一个字符串拼接有三种方法:加号,contact方法,StringBuffer或者StringBuilder的append方法,其中加号是最常用的.其他两种方式偶尔会出现在一些开源项目中,那么这三者有 ...