代码:

#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. Windows7下caffe-ssd-microsoft下编译

    整个编译可谓漫长 编译了两天 网上教程也很多 但是也很杂 遇到各种错误 总归是编完了 1.下载Windows版本的Caffe-SSD源码 下载链接:https://github.com/conner9 ...

  2. Spring 错误日志

    13:19:14.437 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListen ...

  3. Android Studio连接夜神模拟器

    运行-cmd,进入夜神模拟器安装目录,进入目录下的bin 执行Nox_adb.exe connect 127.0.0.1:62001命令,connect左右都有空格. 执行命令后就可以连接到夜神模拟器 ...

  4. ArrayList 源码

    1.ArrayList的类关系: 2.属性及方法      2.1 构造           三个构造方法分别对应:                通过传入初始化容器大小构造数组列表         ...

  5. OpenCV: 图像连通域检测的递归算法

    序言:清除链接边缘,可以使用数组进行递归运算; 连通域检测的递归算法是定义级别的检测算法,且是无优化和无语义失误的. 同样可用于寻找连通域 void ClearEdge(CvMat* MM,CvPoi ...

  6. Repeater + 分页控件 AspNetPager 研究

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs ...

  7. apicloud 第三方登录授权、微信、扣扣、微博登录授权

    授权登录.接入第三方的配置 例如:微信的登录授权. 首先在模块里面添加 wx 这个模块,然后在项目的配置文件里面进行配置. 配置的时候要现在微信开放平台 https://open.weixin.qq. ...

  8. H5-data属性的一个问题

    关于前端存数据的问题,前面写过一个博客:前端页面存取数据 看个例子: <!DOCTYPE html> <html lang="en"> <head&g ...

  9. Python字符串格式化--formate()的应用

    1.简单运用字符串类型格式化采用format()方法,基本使用格式是:转自 <模板字符串>.format(<逗号分隔的参数>) 调用format()方法后会返回一个新的字符串, ...

  10. vue-属性传值 props

    props属性传值 1.传具体的值  string(字符串) number(数值) boolean(布尔) 2.传一个引用 array(数组)  object(对象) ----传引用----- 代码 ...