博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1002 A+B Problem 2
阅读量:4322 次
发布时间:2019-06-06

本文共 1846 字,大约阅读时间需要 6 分钟。

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

 

分析:高精度大数加法,肯定用数组来解决,注意小坑。。。

#include 
#include
#define MAX_LENTH 1001int main(){ char s1[MAX_LENTH],s2[MAX_LENTH]; int a[MAX_LENTH],b[MAX_LENTH],c[MAX_LENTH]; //a用来储存第一个数,b第二个数,c是a+b; int n,i,j,l1,l2,z; scanf("%d",&n); for(i=0;i
=10) { c[j+1]+=c[j]/10; c[j]=c[j]%10; } } printf( "Case %d:\n",i+1); printf("%s + %s = ",s1,s2); z=0; //确定首位 for(j=MAX_LENTH-1;j>=0;j--) { if(z==0) { if(c[j]!=0){ printf("%d",c[j]); z=1; } } else printf("%d",c[j]); } if(z==0) //和为0 printf("0"); if(i

转载于:https://www.cnblogs.com/kugwzk/p/5070179.html

你可能感兴趣的文章
NSTextView 文字链接的定制化
查看>>
第五天站立会议内容
查看>>
ATMEGA16 IOport相关汇总
查看>>
面试题5:字符串替换空格
查看>>
[Codevs] 线段树练习5
查看>>
Amazon
查看>>
hMailServer搭建简单邮件系统
查看>>
从零开始学习jQuery
查看>>
opacity半透明兼容ie8。。。。ie8半透明
查看>>
CDOJ_24 八球胜负
查看>>
Alpha 冲刺 (7/10)
查看>>
一款jQuery打造的具有多功能切换的幻灯片特效
查看>>
SNMP从入门到开发:进阶篇
查看>>
@ServletComponentScan ,@ComponentScan,@Configuration 解析
查看>>
unity3d 射弹基础案例代码分析
查看>>
thinksns 分页数据
查看>>
os模块
查看>>
最短路径(SP)问题相关算法与模板
查看>>
js算法之最常用的排序
查看>>
Python——交互式图形编程
查看>>