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 ;
}

最新文章

  1. 高效 Java Web 开发框架 JessMA v3.3.1 正式发布
  2. mac 下搭建php 编程环境全过程
  3. 【elasticsearch】python下的使用
  4. BZOJ3570 : DZY Loves Physics I
  5. The Separator in Grid_BFS
  6. Java 快排
  7. Mac下安装 MongoDB
  8. highchart
  9. 24 服务AIDL
  10. 浏览器仿EXCEL表格插件 版本更新 - 智表ZCELL产品V1.3.2更新
  11. 理论铺垫:阻塞IO、非阻塞IO、IO多路复用/事件驱动IO(单线程高并发原理)、异步IO
  12. Python字符串与格式化的一点用法
  13. vim编辑器的设置
  14. 微信小程序 table 简单测试
  15. Ext Js 6.2.1 classic grid 滚动条bug解决方案
  16. java ----&gt; 注解/反射
  17. 修改Linux下的文件以及文件夹的权限
  18. 星系炸弹-2015省赛C语言A组第二题
  19. jar 命令详解
  20. java后台读取/解析 excel表格

热门文章

  1. (转)如何在windows 2008 安装IIS
  2. 南阳ACM 题目71:独木舟上的旅行 Java版
  3. LightOJ 1321 - Sending Packets 简单最短路+期望
  4. 【设计模式】 模式PK:门面模式VS中介者模式
  5. 【设计模式】 模式PK:策略模式VS桥梁模式
  6. PHP系统编程--02.PHP守护进程化
  7. 在Linux系统里运行shutdown.sh命令关闭Tomcat时出现错误提示
  8. Bzoj4710 [Jsoi2011]分特产
  9. 【NOIP】提高组2016 蚯蚓
  10. Python学习笔记 - day10 - 正则表达式