代码:

#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(大正整数相加)的更多相关文章

  1. 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)

    数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...

  2. HDU 1002 A + B Problem II(大整数相加)

    A + B Problem II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  3. 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) ...

  4. hdu 1002.A + B Problem II 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...

  5. HDU 1002 A + B Problem II

    A + B Problem II   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted ...

  6. HDU 1002 - A + B Problem II - [高精度]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...

  7. 大数加法~HDU 1002 A + B Problem II

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...

  8. HDU 1002 A + B Problem II (大数加法)

    题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...

  9. HDU 1002 A + B Problem II(AC代码)

    #include <stdio.h> #include <string.h> #define MAX 1009 int main() { },b[MAX]={}; ,z=,r= ...

随机推荐

  1. JavaScript学习三

    2019-05-30 20:38:50 逻辑运算符 && || ! !如果对非布尔值取反,则将会把数值变成布尔值,然后再取反 隐式类型转化 为任意的数据类型做两次非运算,既可将其转换成 ...

  2. CodeForces 680A&680B&680C&680D Round#356

    昨天晚上实在是=_=困...(浪了一天)就没有去打Codeforces 中午醒来看看题,还不太难. A题:模拟(水题 3minAC) // by Sirius_Ren #include <cst ...

  3. python--6、常用模块

    time与datetime模块 time模块,用于输出时间 在Python中,用这几种方式来表示时间: 时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按 ...

  4. Gradle 自定义Task 打Jar包

    可以作为Jar包内容的有两个地方: : build/intermediates/bundles/release/ 下的classes.jar : build/intermediates/classes ...

  5. (1)dotnet开源电商系统-brnshop&brnMall 和老外开发的nopCommerce(dotnet两套电商来PK--第一篇)

    一直想做电商软件,但是实在不想学PHP了,所以前后关注了这两个开源电商系统.一个是国人出品的,一个据说是俄罗斯人写得(不知道对不对).目前两个开源软件都在学习了解中,以下的博文可能会涉及到这两套系统, ...

  6. js 响应事件

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. 怎么从传统的盒子思想转为Flex 布局(css)

    前端进化很快,总是有新的技术出来,开始可能有些人用惯了盒子模型的思想 依赖 display属性 + position属性 + float属性.这三大件.它对于那些特殊布局非常不方便 我们就来看看Fle ...

  8. shell 结合expect实现ssh登录并执行命令

    #!/bin/bash ips=( '127.0.0.1' ) ;i<${#ips[*]};i++)) do expect <<EOF #这里的 expect <<EOF ...

  9. shell脚本—基础知识,变量

    shell脚本本质: 编译型语言 解释型语言 shell编程基本过程 1.建立shell文件 2.赋予shell文件执行权限,使用chmod命令修改权限 3.执行shell文件 shell变量: sh ...

  10. BZOJ 3012: [Usaco2012 Dec]First! 字典树 + tarjan

    Code: #include<bits/stdc++.h> #define maxn 1000003 using namespace std; char str[maxn],strtot[ ...