1C - A + B Problem II
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 // too young and didn't notice that
// "you should not process them by using 32-bit integer"
// and "Output a blank line between two test cases".
#include<stdio.h>
int main()
{
int a, b, t, i;
scanf("%d", &t);
for(i=;i<=t;i++)
{
scanf("%d %d", &a, &b);
printf("Case %d:\n", i);
printf("%d + %d = %d\n", a, b, a+b);
printf("\n");
}
return ;
}
Wrong Answer
// long int is also 32-bit integer.
代码省略
// 不用判断哪个数较长,只要记录答案的长度. 三个数组都要初始化为0!!!
#include<stdio.h>
#include<string.h> int reverse_add(int *a, int *b, int *c, int al, int bl)
{
int i, sum=, k, max;
if(al<bl) max=bl;
else max=al;
k=;
for(i=; i<max; i++)
{
*(c+i)=(*(a+i)+*(b+i)+k)%;
k=(*(a+i)+*(b+i)+k)/;
}
if(k!=)
{
*(c+i)=;
return max+;
}
else return max;
} int main()
{
char s1[], s2[];
int t, k, i, length_a, length_b, rmax;
scanf("%d", &t);
for(k=;k<=t;k++)
{
int a[]={}, b[]={}, c[]={}; /* 三个数组都要初始化 */
scanf("%s %s", s1, s2);
length_a=strlen(s1); length_b=strlen(s2);
for(i=; i<length_a; i++) a[i]=s1[length_a--i]-'';
for(i=; i<length_b; i++) b[i]=s2[length_b--i]-'';
rmax=reverse_add(a, b, c, length_a, length_b);
printf("Case %d:\n", k);
printf("%s + %s = ", s1, s2);
for(i=; i<rmax; i++) printf("%d", c[rmax--i]);
printf("\n");
if(t>&&k<t) printf("\n");
}
return ;
}
AC
1C - A + B Problem II的更多相关文章
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- nyoj 623 A*B Problem II(矩阵)
A*B Problem II 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大 ...
- HDU 1002 A + B Problem II
A + B Problem II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16104 Accepted ...
- A + B Problem II
之前总是在查阅别人的文档,看着其他人的博客,自己心里总有一份冲动,想记录一下自己学习的经历.学习算法有一段时间了,于是想从算法开始自己的博客生涯O(∩_∩)O~~ 今天在网上看了一道大数相加(高精度) ...
- nyoj 103 A + B problem II
点击打开链接 A+B Problem II 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 I have a very simple problem for you. G ...
- hdu 1023 Train Problem II
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...
- HDU1002 -A + B Problem II(大数a+b)
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
- hdoj 1002 A + B Problem II
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- 6.面向对象 -类.md
目录 1. static: 2. 类在内存中,每一个类在创建在栈内存中,当创建一个对象的时候,将非类变量再堆内存中创建,而类变量是不会因为创建对象而在堆中重新创建 3. 对象.引用和指针: 4. 类名 ...
- JAVAWEB 一一 SpringMVC(注解)
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2 ...
- 吴裕雄 python深度学习与实践(3)
import threading, time def doWaiting(): print('start waiting:', time.strftime('%S')) time.sleep(3) p ...
- Redis Cluster 添加/删除 完整折腾步骤
Redis还是挺好玩的,今天测试了集群的添加.删除节点.重分配slot等.更深入的理解redis的游戏规则.步骤繁多,但是详细. 环境解释: 我是在一台Centos 6.9上测试的,各个redis节点 ...
- Applese的毒气炸弹-最小生成树Kruskal算法
链接:https://ac.nowcoder.com/acm/contest/330/G来源:牛客网 题目描述 众所周知,Applese 是个很强的选手,它的化学一定很好. 今天他又AK了一套题觉得很 ...
- 2018面向对象程序设计(Java)第3周学习指导及要求
2018面向对象程序设计(Java) 第3周学习指导及要求(2018.9.11-2018.9.16) 学习目标 适应老师教学方式,能按照自主学习要求完成本周理论知识学习: 掌握Java Appli ...
- Ubuntu系统下手动释放内存
有时候,像mongo这种,对内存只吃不吐的,我们要手动释放一下. drop_caches的详细文档如下:Writing to this will cause the kernel to drop cl ...
- js增减日期
参考 https://www.cnblogs.com/gmq-sh/p/5194706.html date.setDate(date.getDate() + 3);
- CSS 变量教程
一.变量的声明 声明变量的时候,变量名前面要加两根连词线(--). body { --foo: #7F583F; --bar: #F7EFD2; } 上面代码中,body选择器里面声明了两个变量:-- ...
- Django项目之客户
关于客户的操作 主页(被继承) {% load static %} <!DOCTYPE html> <html lang="en"> <head> ...