注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Minary_Acdream

http://f10.moe/

 
 
 

日志

 
 

[hdu]1002 A + B Problem II  

2012-07-29 16:15:43|  分类: HDU |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

A + B Problem II

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


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<iostream>
#include<string>
using namespace std;
int main()
{
int N;
cin>>N;
for(int k = 1;k <= N;k ++)
{
string a,b,sum;
cin>>a>>b;
if(k != 1)cout<<endl;
cout<<"Case "<<k<<":"<<endl;
cout<<a<<" + "<<b<<" = ";

int alen = a.length(),blen = b.length(),max;
if(alen >= blen)
{
sum = a;
for(int i = 0;i < blen;i ++)
sum[alen - i - 1] = sum[alen - i - 1] + b[blen - i - 1] - '0';
}
else
{
sum = b;
for(int i = 0;i < alen;i ++)
sum[blen - i - 1] = sum[blen - i - 1] + a[alen - i - 1] - '0';
}
for(int i = sum.length() - 1; i > 0;i --)
{
if(sum[i] > '9')
{
sum[i] -= 10;
sum[i - 1] ++;
}
}
if(sum[0] > '9')
{
sum[0] -= 10;
sum = "1" + sum;
}
cout<<sum<<endl;
}
}


  评论这张
 
阅读(214)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018