HDU-1002(简单大数加法)
A + B Problem II
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <istream>
#include <ostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
using namespace std;
#define INF 100000
typedef long long ll;
const int maxn=;
struct BigInteger {
static const int BASE = ;
static const int WIDTH = ;
vector<int> s; BigInteger(long long num = ) { *this = num; }
BigInteger operator = (long long num) {
s.clear();
do {
s.push_back(num % BASE);
num /= BASE;
} while(num > );
return *this;
}
BigInteger operator = (const string& str) {
s.clear();
int x, len = (str.length() - ) / WIDTH + ;
for(int i = ; i < len; i++) {
int end = str.length() - i*WIDTH;
int start = max(, end - WIDTH);
sscanf(str.substr(start, end-start).c_str(), "%d", &x);
s.push_back(x);
}
return *this;
}
BigInteger operator + (const BigInteger& b) const {
BigInteger c;
c.s.clear();
for(int i = , g = ; ; i++) {
if(g == && i >= s.size() && i >= b.s.size()) break;
int x = g;
if(i < s.size()) x += s[i];
if(i < b.s.size()) x += b.s[i];
c.s.push_back(x % BASE);
g = x / BASE;
}
return c;
}
}; ostream& operator << (ostream &out, const BigInteger& x) {
out << x.s.back();
for(int i = x.s.size()-; i >= ; i--) {
char buf[];
sprintf(buf, "%08d", x.s[i]);
for(int j = ; j < strlen(buf); j++) out << buf[j];
}
return out;
} istream& operator >> (istream &in, BigInteger& x) {
string s;
if(!(in >> s)) return in;
x = s;
return in;
}
set<BigInteger> s; int main()
{
int t,times=,tmp;
BigInteger a,b;
scanf("%d",&t);
tmp=t;
while(t--){
cin>>a>>b;
BigInteger sum=a+b;
printf("Case %d:\n",++times);
cout<<a<<" + "<<b<<" = "<<sum<<endl;
if(times!=tmp) printf("\n");
}
return ;
}
HDU-1002(简单大数加法)的更多相关文章
- hdu 1002 Java 大数 加法
http://acm.hdu.edu.cn/showproblem.php?pid=1002 PE 由于最后一个CASE不须要输出空行 import java.math.BigInteger; i ...
- hdu 5718(Oracle)大数加法
曾经有一位国王,统治着一片未名之地.他膝下有三个女儿. 三个女儿中最年轻漂亮的当属Psyche.她的父亲不确定她未来的命运,于是他来到Delphi神庙求神谕. 神谕可以看作一个不含前导零的正整数n n ...
- hdu 1002 java 大数相加
package Main; //import java.io.InputStream; import java.math.BigDecimal; import java.util.Scanner; p ...
- hdu 1002(大数)
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 大数加法~HDU 1002 A + B Problem II
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...
- 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...
- hdu 1002 A + B Problem II【大数加法】
题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...
- HDU 1041 Computer Transformation (简单大数)
Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...
- HDU 1002 A - A + B Problem II (大数问题)
原题代号:HDU 1002 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 原题描述: Problem Description I have a ...
随机推荐
- NOI2010海拔
2007: [Noi2010]海拔 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 1302 Solved: 612[Submit][Status] ...
- 对 Azure Backup 的常见配置问题进行故障排除
Giridhar Mosay云 + Enterprise 项目经理 这篇博客文章有助于解决 Microsoft云备份解决方案(即 Azure Backup)的常见配置问题.客户通常会在安装或注册 ...
- TreeMap源码解析
1.TreeMap介绍 TreeMap是一个通过红黑树实现有序的key-value集合. TreeMap继承AbstractMap,也即实现了Map,它是一个Map集合 TreeMap实现了Navig ...
- SQL Server查询性能优化——覆盖索引(二)
在SQL Server 查询性能优化——覆盖索引(一)中讲了覆盖索引的一些理论. 本文将具体讲一下使用不同索引对查询性能的影响. 下面通过实例,来查看不同的索引结构,如聚集索引.非聚集索引.组合索引等 ...
- oracle 中的truncate 和delete
一.查询表大小,块多少语句 Select SEGMENT_Name,BYTES,BLOCKS,Extents From dba_segments Where segment_name In('BAI_ ...
- 关于Windows Azure的常见问题-注册问题FAQ
注册问题 手机验证出现问题怎么办? 当您输入发送到手机里的验证码到文本框时,您需要点击右侧的“验证代码”的按钮,待按钮转变为“绿色对勾”的标识后,您可以点击“继续”来完成余下的注册步骤.每一个手 机号 ...
- 搭建集群必备:windows如何使用Xshell远程连接(SSH)Linux
出处about云(http://www.aboutyun.com/blog-61-22.html)欢迎访问我的博客 首先介绍一下环境: (主机)操作系统:win7 虚拟机:vmware worksta ...
- 并查集 poj1611&poj2492
poj1611 简单题 代码中id记录父节点,sz记录子树规模.一个集合为一棵树. #include <iostream> #include <cstdio> using na ...
- linux定时运行命令脚本——crontab
cron和crontab定时任务: http://blog.csdn.net/ithomer/article/details/6817019 http://blog.sina.com.cn/s/blo ...
- 用java面向对象的思想实现的汉诺塔问题
package hanoi.com; public class Disc { private String name; private int level; public Disc(){ name = ...