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

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

A + B Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 177301    Accepted Submission(s): 33930

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 1002using namespace std;int main(){ int T,c[MAX],i,j,k,alen,blen,clen,cnt,carry,sum; string a,b; cin>>T; cnt=0; while(cnt
>a>>b; alen = a.length(); blen = b.length(); if(alen>blen)clen=blen; else clen = alen; for(i=alen-1,j=blen-1,k=0,carry = 0;k
9){carry=1;sum-=10;} else carry = 0; c[k]=sum; } for(;i>-1;i--,k++) { sum = a[i]+carry-48; if(sum > 9){carry = 1;sum -= 10;} else carry = 0; c[k] = sum; } for(;j>-1;j--,k++) { sum = b[j] + carry - 48; if(sum > 9) { carry = 1; sum -= 10; } else carry = 0; c[k] = sum; } if(carry){c[k]=1;k++;} cout<<"Case "<
<<":"<

 

转载于:https://www.cnblogs.com/littlehoom/p/3427519.html

你可能感兴趣的文章
62. Unique Paths
查看>>
告诉你微信域名被封的原因和防封方案
查看>>
七个你没用过的炫酷开发工具推荐
查看>>
深度解析利用ES6进行Promise封装总结
查看>>
css的content属性
查看>>
熬过了互联网“寒冬”,接下来的金三银四你该怎么面试进BAT?
查看>>
Java 开源库精选(持续更新)
查看>>
Scrum联盟发布2015年Scrum状况报告
查看>>
在 Ubuntu 16.04 LTS 上安装 Python 3.6.0
查看>>
CloudCare容器技术白皮书
查看>>
苦酒入喉心作痛,红酒入鹅鹅想哭——震惊!勒索病毒想哭靠wine感染了Ubuntu16.04 ...
查看>>
Kubernetes Nginx Ingress Controller源码分析
查看>>
Linux下区分物理CPU、逻辑CPU和CPU核数
查看>>
第二十一章:变换(三)
查看>>
同步异步阻塞非阻塞杂记
查看>>
2018年中国银行业十件大事,“Fintech深度融合,科技子公司遍地” ...
查看>>
Git SSH 连接phacility服务器
查看>>
【客户案例】智能驾驶行业如何上云?
查看>>
foreman源NO_PUBKEY 6F8600B9563278F6
查看>>
揭秘:蚂蚁金服bPaaS究竟是什么?
查看>>