A + B Problem II(1002)
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.
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.
1 2
112233445566778899 998877665544332211
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std; int main()
{
int n , ans = ;
cin >> n ;
while(n --)
{
ans++ ;
char a[] = {}, b[] ={} ;
int c[] ={}, d[] = {} , e[] ={};
scanf("%s%s" , &a , &b);
int len1 = strlen(a) ;
int len2 = strlen(b) ;
int len = max(len1 , len2);
int j = ;
for(int i = len1 - ; i >= ; i--)
{
c[j++] = a[i] - ;
}
j = ;
for(int i = len2 - ; i >= ; i--)
{
d[j++] = b[i] - ;
}
int k = ;
for(int i = ; i < len ; i++)
{
e[i] = (c[i] + d[i] + k) % ;
k = (c[i] + d[i] + k) / ;
}
cout << "Case " << ans << ':' << endl ;
printf("%s + %s = " , a , b);
if(!k)
{
for(int i = len - ; i >= ; i--)
cout << e[i] ;
cout << endl ;
}
else
{
e[len] = k ;
for(int i = len ; i >= ; i--)
cout << e[i] ;
cout << endl ;
}
if(n != )
printf("\n"); }
return ;
}
A + B Problem II(1002)的更多相关文章
- 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 (a,b都不超过1000位) 思路:用数组存储 第一道大数的题目,虽然很水,纪念一下! 代码: #include<cstdio> #include<cstring ...
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
- 【BZOJ2998】Problem A(动态规划)
[BZOJ2998]Problem A(动态规划) 题面 BZOJ 题解 一个人的成绩范围可以确定为一个区间 这样就变成了 选择若干区间,不重合, 每个区间有个权值,求最大权值和 这样就可直接\(dp ...
- 【Luogu1414】又是毕业季II(数论)
[Luogu1414]又是毕业季II(数论) 题面 题目背景 "叮铃铃铃",随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘 ...
- 【BZOJ2302】[HAOI2011]Problem C(动态规划)
[BZOJ2302][HAOI2011]Problem C(动态规划) 题面 BZOJ 洛谷 题解 首先如果\(m=0\)即没有特殊限制的话,那么就和这道题目基本上是一样的. 然而这题也有属于这题的性 ...
- HDU 1002 A + B Problem II(大整数相加)
A + B Problem II Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- HDU 1002:A + B Problem II(大数相加)
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- A + B Problem II(杭电1002)
/*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A an ...
随机推荐
- 关于CSS你应该知道的基础知识 - 盒模型篇
浏览器渲染引擎通过盒模型的方式来布局html元素.我们可以将每一个html元素都看做是一个盒子,每一个盒子都有长和款,多个这样的盒子组成了我们的网页. Margin,Border,Padding 每一 ...
- MongoDB的$作为下标的用法
在MongoDB中有一个非常神奇的符号 "$" "$" 在 update 中 加上关键字 就 变成了 修改器 其实 "$" 字符 独立出现 ...
- hbase完全分布式搭建
1.解压缩hbase的软件包,使用命令: tar -zxvf hbase-1.3.0-bin.tar.gz 2.进入hbase的配置目录,在hbase-env.sh文件里面加入java环境变量.即: ...
- Win10离线安装.NET Framework 3.5的方法补充(附cab格式离线安装包下载) - 转载
MS酋长很早以前已经分享了<Win10离线安装.NET Framework 3.5的方法技巧>,同时分享了exe格式的.NET Framework 3.5离线安装包下载地址.但有部分网友反 ...
- 链表中倒数第k个节点(python)
题目描述 输入一个链表,输出该链表中倒数第k个结点. 无力吐槽牛客网... class Solution: def FindKthToTail(self, head, k): # write code ...
- LeetCode--617--合并二叉树(python)
给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠. 你需要将他们合并为一个新的二叉树.合并的规则是如果两个节点重叠,那么将他们的值相加作为节点合并后的新值,否则不为 ...
- Eclipse设置类和方法的注释模板
一.打开设置模板的窗口:Window->Preference->Java->Code Style->Code Template展开Comments,最常用的就是类和方法的注释, ...
- 跳马(Knight Moves), ZOJ1091, POJ2243 x
跳马(Knight Moves), ZOJ1091, POJ2243 题目描述: 给定象棋棋盘上两个位置 a 和 b,编写程序,计算马从位置 a 跳到位置 b 所需步数的最小值. 输入描述: 输入文件 ...
- Android and HTML5 开发手机应用(转载)
作为一个WEB开发者,HTML5让我兴奋,因为它可以将桌面应用程序功能带入浏览器中.但在国内,看着到处横行的IE8版本以下的浏览器,觉得到能大规模使用HTML5技术的那天,还遥遥无期.但面对iOS及A ...
- 转载:String.format()的详细用法
转载自:https://blog.csdn.net/anita9999/article/details/82346552 问题 在开发的时候一段字符串的中间某一部分是需要可变的 比如一个Textvie ...