A + B Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 435932    Accepted Submission(s): 84825

Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
 
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
 
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
 
Sample Input
2
1 2
112233445566778899 998877665544332211
 
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
 
Author
Ignatius.L
 

代码:

 #include<stdio.h>
#include<string.h>
int main(){
char a[],b[];
int c[],d[],ans[];
int n,i,k,j,h,t,l;
int len1,len2;
scanf("%d",&n);
h=;
while(n--){
h+=;
for(i=;i<;i++){
c[i]=d[i]=;
ans[i]=;
}
scanf("%s %s",&a,&b);
len1=strlen(a);
len2=strlen(b);
for(i=;i<len1;i++){
c[i]=a[i]-'';
}
for(i=;i<len2;i++){
d[i]=b[i]-'';
}
printf("Case %d:\n",h);
for(i=;i<len1;i++)
printf("%d",c[i]);
printf(" + ");
for(i=;i<len2;i++)
printf("%d",d[i]);
printf(" = ");
for(i=,j=len1-;i<len1/;i++,j--){
t=c[j];
c[j]=c[i];
c[i]=t;
}
for(i=,j=len2-;i<len2/;i++,j--){
t=d[j];
d[j]=d[i];
d[i]=t;
}
l=len1>len2?len1:len2;
for(i=,k=;i<=l;i++,k++){
if(c[i]+d[i]<)
ans[k]=c[i]+d[i];
else{
ans[k]=(c[i]+d[i])%;
c[i+]+=(c[i]+d[i])/;
} }
for(j=k-;j>=;j--){
if(j==k-&&ans[j]==)
continue;
printf("%d",ans[j]);
}
if(n==)
printf("\n");
else
printf("\n\n");
}
return ;
}

HDU 1002.A + B Problem II-数组模拟-大数相加的更多相关文章

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

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

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

    代码: #include<cstdio> #include<cstring> #define Min(a,b) ((a)<(b)?(a):(b)) using names ...

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

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

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

  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【大数加法】

    题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...

  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 - [高精度]

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

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

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

随机推荐

  1. javascript实现购物车思路

    /* 思路: 第一步:获取所要操作的节点对象 第二步:当页面加载完后,需要计算本地cookie存了多少[个]商品,把个数赋值给count 第三步:为每一个商品对应的添加购物车按钮绑定一个点击事件onc ...

  2. 51Nod 1090 3个数之和

    Input示例 7 -3 -2 -1 0 1 2 3 Output示例 -3 0 3 -3 1 2 -2 -1 3 -2 0 2 -1 0 1 #include "bits/stdc++.h ...

  3. 【BZOJ3884】上帝与集合的正确用法 [欧拉定理]

    上帝与集合的正确用法 Time Limit: 5 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description Input 第一行一个T ...

  4. 「6月雅礼集训 2017 Day5」仰望星空

    [题目大意] 给你$n$个点,被一个半径为$R$的元圆划分成内(包含边界).外两个部分. 要连若干线,每个点只能连一条线,不存在重点和三点共线. 线只能连在内部点和外部点之间,线长度不超过$d$. 如 ...

  5. 【CodeForces】601 D. Acyclic Organic Compounds

    [题目]D. Acyclic Organic Compounds [题意]给定一棵带点权树,每个点有一个字符,定义一个结点的字符串数为往下延伸能得到的不重复字符串数,求min(点权+字符串数),n&l ...

  6. C题 hdu 1408 盐水的故事

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1408 盐水的故事 Time Limit: 2000/1000 MS (Java/Others)     ...

  7. Eclipse连接海马模拟器

    找到海马模拟器安装目录: 使用cmd 命令进入命令行:D: cd:D:\Program Files (x86)\Droid4X 进入模拟器所在目录 运行adb connect 127.0.0.1:26 ...

  8. sk_buff结构

    sk_buff结构用来描述已接收或者待发送的数据报文信息:skb在不同网络协议层之间传递,可被用于不同网络协议,如二层的mac或其他链路层协议,三层的ip,四层的tcp或者udp协议,其中某些成员变量 ...

  9. linux驱动基础系列--Linux 串口、usb转串口驱动分析

    前言 主要是想对Linux 串口.usb转串口驱动框架有一个整体的把控,因此会忽略某些细节,同时里面涉及到的一些驱动基础,比如字符设备驱动.平台驱动等也不进行详细说明原理.如果有任何错误地方,请指出, ...

  10. python实战===用python识别图片中的中文

    需要安装的模块 PIL pytesseract 需要下载的工具: http://download.csdn.net/download/bo_mask/10196285 因为之前百度云的链接总失效,所以 ...