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 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的更多相关文章
- 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个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. ...
随机推荐
- Java中Scanner的使用方法
Scanner是SDK1.5新增的一个类,但是使用该类创建一个对象.Scanner reader=new Scanner(System.in); 然后reader对象调用下列方法(函数),读取用户 ...
- windows下远程adb
Android 使用 adb命令 远程安装apk cmd下到你的adb文件夹,一般在platform-tools下. adb devices 列出全部设备 adb connect xxx.xxx.xx ...
- mahout算法源码分析之Itembased Collaborative Filtering(三)RowSimilarityJob验证
Mahout版本:0.7,hadoop版本:1.0.4,jdk:1.7.0_25 64bit. 本篇分析上篇的分析是否正确,主要是编写上篇输出文件的读取以及添加log信息打印相关变量. 首先,编写下面 ...
- 配置Windows Live Writer,写cnblogs博客
引言 以前写博客一般都是联网在cnblogs上面写,不好的地方就是不联网就写不了,当然我们也可以先记录在word文件,等联网在从word里面拷贝出来发布到cnblogs上面,但是样式这些 ...
- java_java 利用JAX-RS快速开发RESTful 服务
JAX-RS(Java API for RESTful Web Services)同样也是JSR的一部分,详细规范定义见 https://jcp.org/en/jsr/detail?id=311 .从 ...
- 小白日记6:kali渗透测试之被动信息收集(五)-Recon-ng
Recon-ng Recon-NG是由python编写的一个开源的Web侦查(信息收集)框架.Recon-ng框架是一个全特性的工具,使用它可以自动的收集信息和网络侦查.其命令格式与Metasploi ...
- Number Game poj1143
Description Christine and Matt are playing an exciting game they just invented: the Number Game. The ...
- [转]一步步教你如何在 Visual Studio 2013 上使用 Github
介绍 我承认越是能将事情变简单的工具我越会更多地使用它.尽管我已经知道了足够的命令来使用Github,但我宁愿它被集成到IDE中.在本教程中,我会告诉你使用Visual Studio 2013如何实现 ...
- Android(java)学习笔记78:设计模式之单例模式
单例模式代码示例: 1. 单例模式之饿汉式: package cn.itcast_03; public class Student { // 构造私有 private Student() { } // ...
- 高德地图 JavaScript API 开发系列教程(一)
高德地图 API 提供包括 Web API 即 JavaScript API,Android API,定位API,IOS API,WP API,Win8 API等,本系列教程主要针对高德 JavaSc ...