hdu 1002 A + B Problem II(大正整数相加)
代码:
#include<cstdio>
#include<cstring>
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std; char s1[10000],s2[10000],s3[10000]; int main()
{
int t;
scanf("%d",&t);
int tt=0;
while(t--)
{
++tt;
if(tt!=1)
printf("\n");
scanf("%s%s",s1,s2);
int len1,len2,len3;
len1=strlen(s1);
len2=strlen(s2);
len3=Min(len1,len2);
int k=0;
int i=len1-1;
int j=len2-1;
int pos=0;
while(len3--)
{
int temp=(s1[i--]-'0'+s2[j--]-'0'+k);
s3[pos++]=(temp%10+'0');
k=temp/10;
}
if(i==-1&&j==-1)
{
if(k!=0)
s3[pos++]=k+'0';
}
else if(i==-1&&j!=-1)
{ while(j>=0)
{
int temp=s2[j--]-'0'+k;
s3[pos++]=(temp%10+'0');
k=temp/10;
}
if(k!=0)
s3[pos++]=k+'0';
}
else
{
while(i>=0)
{
int temp=s1[i--]-'0'+k;
s3[pos++]=(temp%10+'0');
k=temp/10;
}
if(k!=0)
s3[pos++]=k+'0';
}
printf("Case %d:\n",tt);
printf("%s + %s = ",s1,s2);
for(i=pos-1;i>=0;i--)
{
printf("%c",s3[i]);
}
printf("\n");
}
return 0;
}
hdu 1002 A + B Problem II(大正整数相加)的更多相关文章
- 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...
- HDU 1002 A + B Problem II(大整数相加)
A + B Problem II Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- HDU 1002 A + B Problem II(高精度加法(C++/Java))
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 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...
- HDU 1002 A + B Problem II
A + B Problem II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16104 Accepted ...
- HDU 1002 - A + B Problem II - [高精度]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...
- 大数加法~HDU 1002 A + B Problem II
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...
- HDU 1002 A + B Problem II (大数加法)
题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...
- HDU 1002 A + B Problem II(AC代码)
#include <stdio.h> #include <string.h> #define MAX 1009 int main() { },b[MAX]={}; ,z=,r= ...
随机推荐
- python之路——常用模块
阅读目录 认识模块 什么是模块 模块的导入和使用 常用模块一 collections模块 时间模块 random模块 os模块 sys模块 序列化模块 re模块 常用模块二 hashlib模块 con ...
- BZOJ 4525 二分
思路: 满足二分性质... 二分一下 就完了 //By SiriusRen #include <cstdio> #include <algorithm> using ...
- Redis学习笔记(二)-key相关命令
Redis支持的各种数据类型包括string,list ,set ,sorted set 和hash . Redis本质上一个key-value db,所以我们首先来看看他的key.首先key也是字符 ...
- Spring学习笔记之aop动态代理(3)
Spring学习笔记之aop动态代理(3) 1.0 静态代理模式的缺点: 1.在该系统中有多少的dao就的写多少的proxy,麻烦 2.如果目标接口有方法的改动,则proxy也需要改动. Person ...
- redis 主从复制 redis 探索
http://blog.csdn.net/column/details/12804.html
- 【第三课】kaggle案例分析三
Evernote Export 比赛题目介绍 TalkingData是中国最大的第三方移动数据平台,移动设备用户日常的选择和行为用户画像.目前,TalkingData正在寻求每天在中国活跃的5亿移动设 ...
- Django—链接MySQL
Djalgo基础配置方法 静态文件配置方法 1 所有的静态文件都放在 static 文件夹下,例如Bootstrap值类的第三方库,通常 static 文件下会创建 css image js 文件,用 ...
- 用doxygen风格注释代码生成文档
目录 用doxygen风格注释代码生成文档 1. 说明 2. 具体操作 2.1 生成头部注释 2.2 安装doxygen 2.3 工程配置 3. 总结 用doxygen风格注释代码生成文档 1. 说明 ...
- vue 中引入Jquery插件
import $ from '../../static/js/jquery.min.js' window.jQuery = $; require('../../static/js/jquery.zoo ...
- shell常用语法
for.if条件: https://blog.51cto.com/qiufengsong/1252889 一.for循环: );do echo $i done ###第一行:seq是指1到10,第二行 ...