HOJ-1002 A + B Problem II

杭电OJ 1002题 A + B Problem II 题目描述 I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. 输入 The first line of the input contains an integer T(1<=T<=20) which means th... 阅读详情

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 Input2

1 2
112233445566778899 998877665544332211

Sample Output

Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

Author

Ignatius.L

Tips

根据题目描述可知,计算两个不超过1000位数字的和,显然,利用已有的int long或是long long 都不能满足题目要求,所以这一题我选择的是将长整数存储成字符串的形式。对字符串的每个数字单独进行处理,满十进一。

Code

#include<iostream>
#include<string>
using namespace std;
string r[10]={"0","1","2","3","4","5","6","7","8","9"};
int main(){
    int n,i,j,cnt=1;
    string str1,str2;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>str1>>str2;
        int len1=str1.size();
        int len2=str2.size();
        int flag=0;
        string rs="";
        for(j=1;j<=len1&&j<=len2;j++){
            int digit=(str1[len1-j]-'0')+(str2[len2-j]-'0')+flag;
//            cout<<"digit:"<<digit<<endl;
            flag=digit/10;
            rs=r[digit%10]+rs;
//            cout<<"*"<<rs<<endl;
        }
        while(j<=len1){
            int digit=(str1[len1-j]-'0')+flag;
            flag=digit/10;
            rs=r[digit%10]+rs;
            j++;
        }
        while (j<=len2) {
            int digit=(str2[len2-j]-'0')+flag;
            flag=digit/10;
            rs=r[digit%10]+rs;
            j++;
        }
        if(cnt!=1)
            cout<<endl;
        if(flag)
            rs=r[flag]+rs;
        cout<<"Case "<<cnt<<":"<<endl;
        cout<<str1<<" + "<<str2<<" = "<<rs<<endl;
        cnt++;
    }
    return 0;
}
大数处理问题(就是用字符串) 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. 立即下载

相关推荐

HOJ1002:A+B+C

注意数据范围,所以要用long long

C语言解题—— 整数a+b(大数运算)

每天更新一道OJ题目,今日介绍简单整数和大数加法的使用方法和示例。I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.这里使用多种解法来对其进行编译。示例:The first line of the input contains an integer T(1...

Xa_L 2978

永磁同步电机定子槽型设计实战:从梨形槽到矩形槽的NVH优化之路

本文深入探讨了永磁同步电机定子槽型设计在NVH优化中的关键作用,对比了梨形槽与矩形槽的性能差异。通过Ansys Maxwell仿真和实际案例,揭示了矩形槽在提升槽满率、降低电磁噪声方面的优势,并总结了五大设计黄金法则,为电机设计工程师提供了实用指导。

weixin_28740299的博客 494

C语言oj中a b怎么做,【HDUOJ】第1002题 A + B Problem II 纯C语言解法

【HUDOJ-1002】1.原题:Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1...

weixin_31730595的博客 493

2025软考中级《数据库系统工程师》案例模拟题合集

1.【说明】某销售企业正在实施电商平台项目,主要功能模块包括用户中心、商品中心、交易中心、支付中心、营销中心等。其中支付中心模块包括了一个账户表:Account (ano, aname, balance),其中属性含义分别为:账户号,账户名称和账户余额。 假设现在存在事务Ti对账户表Account进行余额的修改,系统记录了修改账户表的日志记录,假设更新日志记录表示为 <Ti,A,V1,V2>,表明事务Ti对账户A执行了一个写操作,写操作前账户A的余额是V1,写操作后账户A的余额为V2。<Ti,D

2301_76902257的博客 2329

WinCC ActiveX控件“许可证缺失”故障排查:从注册表修复到系统兼容性全解析

本文深入解析WinCC ActiveX控件报错“未找到许可证信息”的根本原因与解决方案。核心在于系统注册表中控件的设计时许可证密钥丢失或损坏。文章提供了从手动修复注册表、排查64位系统兼容性,到预防性环境部署的全流程专业指南,帮助工程师彻底解决这一常见故障。

oil88的博客 647

【A + B Problem II 】【HDU - 1002 】(高精度加法)

题目: 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...

哇哈哈哈的博客 387

Proteus8.0仿真应用设计(九十一)基于STM32CubeMX、STM32F103C8T6 、FREERTOS、MCP41010(SPI接口)的8位数字电位器应用设计仿真

MCP41010是一款SPI接口的8位数字电位器。

zhusl6688的博客 561

hnust 1032: A + B Problem II

hnust 1032: A + B Problem II

weixin_50950742的博客 987

【一 扣子客户案例合集】【 1.3 识典古籍基于扣子智能助手的古籍数字化全流程技术解析】

古籍数字化智能处理系统全流程解析 本文详细介绍了基于扣子智能助手的古籍数字化解决方案,核心技术包括: 多层级架构设计:采用"云-边-端"三层次架构,整合高精度扫描设备与AI处理模块,实现从物理古籍到结构化数据的全流程自动化。 智能图像处理:通过12道预处理工序(包括畸变校正、污渍去除和对比度增强)处理古籍图像,采用改进的EAST算法和ViT模型实现高精度文字检测与识别,准确率达98.7%。 NLP增强处理:结合Transformer-XL预训练模型和N-gram语言模型进行文本校正,基于

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 1442

Motoman机器人离线编程——Motocom32开发简介

欢迎关注Jungle的Motoman机器人离线编程专栏系列文章: Motoman机器人离线编程——Motocom32开发简介 Motoman机器人离线编程——Visio Studio环境配置 Motoman机器人离线编程——Motocom32库函数的使用与封装 Motoman机器人离线编程——Motocom32参考文献及注意事项 Motoman机器人离线编程——MotocomES介绍 ...

冯Jungle的个人博客 8714

杭电OJ----1002A + B问题II(超大数计算问题)

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 l...

北极星的博客 960

[QMT和ptrade量化交易小白入门]-121、如何用K-means聚类,每月自动筛选高流动性ETF

本专栏主要是介绍QMT和ptrade的基础用法,常见函数,写策略的方法,也会分享一些量化交易的思路,大概会写200篇左右。QMT的相关资料较少,在使用过程中不断的摸索,遇到了一些问题,记录下来和大家一起沟通,共同进步。

木头大左的博客 829

HDU1002 A + B Problem II(待优化)

HOJ1002 A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 434325 Accepted Submission(s): 84533 Problem Description I have a v...

a656418zz的博客 226

Camera HAL Camx — DRQ总结

Camera HAL — DRQ(延迟请求队列)总结 DRQ是CAMX核心层的依赖驱动延迟执行调度器,解决Node处理请求时依赖未就绪的问题。其主要特点包括: 核心功能:当Node处理请求时缺少必要输入(property/metadata/fence),DRQ将其挂起并在依赖满足后重新调度,避免阻塞流水线或丢帧。 系统架构:Session持有主DRQ实例,管理该Session下所有Pipeline Node的依赖;CHI context另有独立DRQ实例专门处理Chi fence同步。 关键数据结构: De

DU_YULIN的博客 77

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

(java)杭电acm 题号:1002 A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 364770    Accepted Submission(s): 70955 Problem Description I have a v

莫風的博客 625

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

A + B Problem II

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&lt;=T&lt;=20) which means the ...

永夜莫明的博客 283

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

A + B Problem II翻译

https://acs.jxnu.edu.cn/problem/HDU1002https://acs.jxnu.edu.cn/problem/HDU1002 描述: I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.(我有一个简单的问题给你,给你两个整数A和B,你的任务是计算A+B的和) 输入: The first line of th

yhnxzw的博客 711

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum o

#include #include using namespace std; int main(void) { string add(string str1, string str2); int n, i, j; cin>>n; string str1, str2, tstr1, tstr2; for(i = 1; i { cout cin>>str1>>str2; t

qq_37414992的博客 3227

喜极而泣!杭电OJ——1002 A + B Problem II

A + B Problem II 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 i

李树花开,风中摇曳 1万+

大整数的加法

#include &lt;iostream&gt;#include &lt;stdio.h&gt;#include &lt;cstring&gt; using namespace std;struct bign{ int d[1000]; int len; bign(){ memset(d,0,sizeof(d)); len=0; }};bign change(char str[]){ big...

QAQ的小耗子的博客 280

杭电 1002[A + B Problem II]

终于解决了这两天纠结死我了。 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 i

Crazy_Frog的专栏 767

HDU1002A + B Problem II

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 foll

LXYDSF的博客 310

大数问题

A+B Problem II 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 I have a very simple problem for you. Given two integers A and B, your job is to calculate the S...

甜晨流年 341
上一篇: 字符串最小表示(超时及优化)
下一篇: B1078 字符串压缩与解压 (20分)
菜菜2022
博客等级 码龄9年 67粉丝 1033原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值