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 ...
随机推荐
- codeigniter实现ajax分页
<?php /** *417 add 主要是实现ajax分页 **/ class MY_Pagination extends CI_Pagination{ public function __c ...
- UIButton图片与文字位置调整
1:左图右文 默认效果就行 2:左文右图 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn addTarget:se ...
- vpn分配多ip的配置
1,创建vpn路由和远程访问 --配置并启用和路由远程访问--自定义配置--选择“vpn访问”,“nat和基本防火墙. 2,vpn配置ip路由选择(nat/基本防火墙)--新增接口(选择本地网卡)-- ...
- [Tommas] UNION 和 UNION ALL 的区别
UNION指令的目的是将两个 SQL 语句的结果合并起来.从这个角度来看,UNION跟 JOIN 有些许类似,因为这两个指令都可以由多个表格中撷取资料.UNION的一个限制是两个 SQL 语句所产生的 ...
- bootstrap布局两列或者多列表单
1, 代码如下: <div class="form-group"> <label for="starttime" class="co ...
- curl post请求
libcurl发送post请求,包括httpheader参数 static size_t getCharCode(void *ptr, size_t size, size_t nmemb, void ...
- (转载)链表环中的入口点 编程之美 leecode 学习
http://www.cnblogs.com/hiddenfox/p/3408931.html 说的很细 /** * Definition for singly-linked list. * clas ...
- NOIP2001 一元三次方程求解
题一 一元三次方程求解(20分) 问题描述 有形如:ax3+bx2+cx+d=0 这样的一个一元三次方程.给出该方程中各项的系数(a,b,c,d 均为实数),并约定该方程存在三个不同实根(根的范 ...
- 微软 Build 2014开发者大会干货整理-1
微软 Build 2014开发者大会第二天的主题演讲主要包含两部分:Microsoft Azure的发展状况,以及 .NET和生态系统的发展介绍.第二天的重点整理也由此分为上下两部分.您可以在Chan ...
- nyoj 678 最小K个数之和
最小K个数之和 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 输入n个整数,输出其中最小的K个数之和.例如输入4,5,1,1,6,2,7,3,3这9个数字,当k=4 ...