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 ...
随机推荐
- jquery formatCurrency货币格式化处理
// This file is part of the jQuery formatCurrency Plugin. // // The jQuery formatCurrency Plugin is ...
- ubuntu操作系统下载
原文网址:http://www.cyberciti.biz/linux-news/download-ubuntu-14-4-cd-dvd-iso-images/ Download of the day ...
- 解决Dagger2和butterknife冲突
dagger2 和 RxJava butterknife 以及 Retrofit使用起来非常酸爽 代码非常干净清晰 动手尝试 配置编译 DaggerAppComponent的时候 出现问题 配置dag ...
- JS中Date.parse方法返回NaN解决方案
Date.parse()方法: //将时间字符串转换为秒数 var date_str = '2013-12-3 18:32:00'; alert(date_str.replace(/-/g,'/')) ...
- cocos2d-x android项目引用so库编译
项目接了几十个渠道平台,每个平台都建了一个Android工程,引用Classes,由于才用java接口类来抽象出平台接口方法,所以每个工程的Android.mk是完全一致的,也就是说libgame.s ...
- 如何在Azure上动态配置IP地址
微软最近对 Windows Azure 网站进行了升级,并启用了IIS8的动态 IP 限制模块.现在,开发人员可以为其网站启用并配置动态 IP 限制功能(或简称 DIPR). 可以通过以下链接查看此 ...
- linux 密码安全脚本
#!/bin/bash #by:osx1260@.com DIESO=/etc/pam.d PAMSO=$(ls $DIESO/* |awk -F'/' '{print $4}') NEPAMUN=' ...
- HW5.25
public class Solution { public static void main(String[] args) { System.out.println(convertMillis(55 ...
- algorithm@ Matrix fast power
一. 什么是快速幂: 快速幂顾名思义,就是快速算某个数的多少次幂.其时间复杂度为 O(log₂N), 与朴素的O(N)相比效率有了极大的提高.一般一个矩阵的n次方,我们会通过连乘n-1次来得到它的n次 ...
- POJ3080 - Blue Jeans(KMP+二分)
题目大意 求N个字符串的最长公共字串 题解 和POJ1226做法一样...注意是字典序最小的...WA了一次 代码: #include <iostream> #include <cs ...