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 ...
随机推荐
- Azure IoT 技术研究系列2
上篇博文中,我们主要介绍了Azure IoT Hub的基本概念.架构.特性: Azure IoT 技术研究系列1-入门篇 本文中,我们继续深入研究,做一个起步示例程序:模拟设备注册到Azure IoT ...
- python基本数据类型常用方法
python基本数据类型 1.整型 1.1 int 1.2 bit_lenght # 当前数字的二进制位数,至少用n位表示 r = age.bit_length() >>> a = ...
- django之logo日志的配置和使用
一:为什么使用日志 假如,在项目调试过程中,在某些地方加上了print()函数,输出了一些调试信息.在项目上线的时候,不要将调试信息暴露出去,但是调试信息还要用,该怎么办?项目测试运行在远端服务器上, ...
- SpringBoot框架(4)-- 类装配及Bean装配监听器
1.普通方式装配类对象 (1)添加带有@Bean注解的方法 User.java(带@Component注解) package com.demo.boot.bootenable.beanDemo1 ...
- echart--如何自定义提示框的内容和样式实例
图例的大概样子 具体设置代码为:
- 超赞的Linux软件分享(持续更新)
开发 Android studio - Android 的官方 IDE:Android Studio 提供在各种类型的安卓设备上构建应用最快的工具. Aptana - Aptana Studio 利用 ...
- POJ 3046 Ant Counting ( 多重集组合数 && 经典DP )
题意 : 有 n 种蚂蚁,第 i 种蚂蚁有ai个,一共有 A 个蚂蚁.不同类别的蚂蚁可以相互区分,但同种类别的蚂蚁不能相互区别.从这些蚂蚁中分别取出S,S+1...B个,一共有多少种取法. 分析 : ...
- Quartus_II官方教程-中文版之SignalTap II
非常实用 187-196 第十二章:调试 Quartus_II官方教程-中文版.pdf
- R 文件读写
Write.table()函数的用法read.table()非常相似,只不过它把数据框写入文件而不是从文件中读取.参数和选项: write.table(x, file = "", ...
- ES6 模板语法和分隔符
let user = 'Barret'; console.log(`Hi ${user}!`); // Hi Barret!