原题代号:HDU 1002

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002

原题描述:

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
 
题目大意:完成长度在1000以内的任意两数相加 (转换成字符串处理)
解法:

# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL; char a[+],b[+],c[+]; int main()
{
int t,sum=;
cin>>t;
while(t--)
{
if(sum)cout<<endl;
char str1[+],str2[+];
mem(a,'\0');
mem(b,'\0');
mem(c,'\0');//因为多组数据,所以清零
cin>>str1;
for(int i=sizeof(a),j=strlen(str1)-; j>=; j--,i--)
a[i]=str1[j]-;
cin>>str2;
for(int i=sizeof(b),j=strlen(str2)-; j>=; j--,i--)//将字符串放在数组末尾,并且将字符转换成ASCLL码所对应的数字
b[i]=str2[j]-;
int num=,i;
for(i=sizeof(a); i>; i--)
{
c[i]=a[i]+b[i]+num;
num=c[i]/;
c[i]%=;
}
printf("Case %d:\n%s + %s = ",++sum,str1,str2);
for(i=;i<=;i++)if(c[i])break;
for(int j=i; j<=sizeof(c); j++)
printf("%d",c[j]);//将大数表示出来
cout<<endl;
}
return ;
}

  

HDU 1002 A - A + B Problem II (大数问题)的更多相关文章

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

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

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

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

  3. hdu1002 A + B Problem II(大数题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/ ...

  4. HDU1002 A + B Problem II 大数问题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java ...

  5. 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) ...

  6. HDU 1023 Train Problem II 大数打表Catalan数

    一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...

  7. A + B Problem II 大数加法

    题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...

  8. 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评

    最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...

  9. hdu1002 A + B Problem II[大数加法]

    目录 题目地址 题干 代码和解释 参考 题目地址 hdu1002 题干 代码和解释 由题意这是一个涉及到大数的加法问题.去看了一眼大数加法的方法感觉头很大,然后突然发现Java可以流氓解决大数问题,毅 ...

随机推荐

  1. 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)

    ubuntu更新软件时 apt-get upgrade 遇到 E: 无法获得锁 /: 资源暂时不可用) E: Unable to acquire the dpkg frontend lock (/va ...

  2. 【Linux开发】jpeglib使用指南

    您可以到www.ijg.org网站下载libjpeg的源码, IJG JPEG Library就是jpeg压缩库,是以源码的形式提供给软件开发人员的,当然在软件包里也有编译好的库文件,我们这里就只用到 ...

  3. Golang中log与fmt区别

    关于使用log与使用fmt的区别 最初的就是直接打印出来,之后一点点升级,比如加上输出的时间,加上goroutine之间的并发操作(打印信息并不能一定按照你规定好的顺序输出来 每次输出的顺序可能会不同 ...

  4. js swich

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  5. JSON.toJSONString时保留null值

    QuoteFieldNames———-输出key时是否使用双引号,默认为true WriteMapNullValue——–是否输出值为null的字段,默认为false WriteNullNumberA ...

  6. C#读取xml节点数据方法小结

    本文实例总结了C#读取xml节点数据的方法.分享给大家供大家参考.具体如下: 第一种: 使用XPath XML的路径我配置在web.config 的appSettings节点下 <appSett ...

  7. Qfile

    打开方式: void AddStudents::write_to_file(QString src){ QFile file("stu.txt"); if (!file.open( ...

  8. K8S工作原理

    kubernetes(k8s)是docker容器用来编排和管理的工具 我们通过kubectl向k8s Master发出指令.kubernetes Master主要是提供API Server.Sched ...

  9. Python 流程控制 超全解析(不可错过)

    流程控制 程序执行结构流程 计算机程序在解决某个具体问题时,包括三种情形,即顺序执行所有的语句.选择执行部分的语句和循环执行部分语句,这正好对应着程序设计中的三种程序执行结构流程:顺序结构.选择结构和 ...

  10. ASSERT()断言

    头文件<assert.h>   作用:用于判断是否有非法的数据,有则程序报告错误,终止运行.(注意是非法情况,而不是错误情况)   ASSERT()和assert()的区别: ASSERT ...