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
 
思路:字符串输入,将两个字符串倒叙输入两个新整型数组(一开始一直在纠结如何倒叙相加)。然后相加进位。注意最后要判断进位是否为0 .
 
注意!!!一定要将两个新的整型数组初始化为0(这长度不一的两个数倒叙相加时不会出错),另外最好用一个新的数组来接受相加结果。。
 
#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)的更多相关文章

  1. nyoj 623 A*B Problem II(矩阵)

    A*B Problem II 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大 ...

  2. hdu 1002 A + B Problem II(大数)

    题意:就是求a+b (a,b都不超过1000位) 思路:用数组存储 第一道大数的题目,虽然很水,纪念一下! 代码: #include<cstdio> #include<cstring ...

  3. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  4. 【BZOJ2998】Problem A(动态规划)

    [BZOJ2998]Problem A(动态规划) 题面 BZOJ 题解 一个人的成绩范围可以确定为一个区间 这样就变成了 选择若干区间,不重合, 每个区间有个权值,求最大权值和 这样就可直接\(dp ...

  5. 【Luogu1414】又是毕业季II(数论)

    [Luogu1414]又是毕业季II(数论) 题面 题目背景 "叮铃铃铃",随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘 ...

  6. 【BZOJ2302】[HAOI2011]Problem C(动态规划)

    [BZOJ2302][HAOI2011]Problem C(动态规划) 题面 BZOJ 洛谷 题解 首先如果\(m=0\)即没有特殊限制的话,那么就和这道题目基本上是一样的. 然而这题也有属于这题的性 ...

  7. HDU 1002 A + B Problem II(大整数相加)

    A + B Problem II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  8. HDU 1002:A + B Problem II(大数相加)

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. A + B Problem II(杭电1002)

    /*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A an ...

随机推荐

  1. VCL界面控件DevExpress VCL Controls发布v18.2.7|附下载

    DevExpress VCL Controls是 Devexpress公司旗下最老牌的用户界面套包.所包含的控件有:数据录入,图表,数据分析,导航,布局,网格,日程管理,样式,打印和工作流等,让您快速 ...

  2. CTF Jarvisoj Web(session.upload_progress.name php 上传进度)

    Jarvisoj Web 题目地址:http://web.jarvisoj.com:32784/index.php <?php //A webshell is wait for you ini_ ...

  3. vue-element添加修改密码弹窗

    1.新建修改密码vue文件CgPwd.vue 代码如下: <template> <!-- 修改密码界面 --> <el-dialog :title="$t('c ...

  4. HDU 5418 Victor and World (状态压缩dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5418 题目大意:有n个结点m条边(有边权)组成的一张连通图(n <16, m<100000 ...

  5. android 如何引用jar包

    首先,把jar包放到项目目录app/libs下,然后是项目引用:三个方法 方法一.添加compile 打开app下的build.gradle,在dependencies里面添加 implementat ...

  6. luogu P1428 小鱼比可爱 x

    P1428 小鱼比可爱 题目描述 人比人,气死人:鱼比鱼,难死鱼.小鱼最近参加了一个“比可爱”比赛,比的是每只鱼的可爱程度.参赛的鱼被从左到右排成一排,头都朝向左边,然后每只鱼会得到一个整数数值,表示 ...

  7. echarts画环形图

    alarmManage(){ let drawLine = echarts.init(document.getElementById('data-alarmManage-table-wrap')); ...

  8. vue2.0 之 douban (三)创建header组件

    1.分析 首页的header背景是绿色的,并且有一个搜索框,其他页面都是灰色的背景,在header的左侧,是一个返回按钮,右侧,有分享或者评论等图标,中间就是header的标题.我们先不做有搜索框的h ...

  9. React-Native 之 GD (十三)数据持久化(realm) 及 公共Cell

    1.数据持久化 数据持久化是移动端的一个重要部分,刚发现 Realm 原来已经支持 React-Native 了 步骤一: 引入 realm $ npm install realm --save 步骤 ...

  10. Python爬虫数据保存到MongoDB中

    MongoDB是一款由C++语言编写的非关系型数据库,是一个基于分布式文件存储的开源数据库系统,其内容存储方式类似于JSON对象,它的字段值可以是其它文档或数组,但其数据类型只能是String文本型. ...