HDU 1002 A + B Problem II
A + B Problem II
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 16104 Accepted: 4547
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
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
思路:
把数值每一位拆开存进数组,利用ASCII码转换数据,然后进行相加。
#include<stdio.h>
#include<string.h>
int main()
{
char a[1003];
char b[1003];
char ans[1003];
int T;
scanf("%d",&T);
int cas = 0 ;
while(T--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(ans,0,sizeof(ans));
scanf("%s",a);
scanf("%s",b);
strrev(a);
strrev(b);
int i;
for(i = 0 ; a[i]&&b[i];i++)
{
ans[i]+=a[i]+b[i]-48;
if(ans[i]>'9'){
ans[i+1]++;
ans[i]-=10;
}
}
while(a[i]){
ans[i]+=a[i];
if(ans[i]>'9'){
ans[i+1]++;
ans[i]-=10;
}
i++;
}
while(b[i]){
ans[i]+=b[i];
if(ans[i]>'9'){
ans[i+1]++;
ans[i]-=10;
}
i++;
}
if(ans[i]==1)ans[i]+=48;
strrev(ans);
strrev(a);
strrev(b);
if(cas)printf("\n");
printf("Case %d:\n",++cas);
printf("%s + %s = %s\n",a,b,ans);
}
}
HDU 1002 A + B Problem II的更多相关文章
- 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...
- HDU 1002 A + B Problem II(高精度加法(C++/Java))
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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 - [高精度]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...
- hdu 1002.A + B Problem II 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...
- 大数加法~HDU 1002 A + B Problem II
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...
- HDU 1002 A + B Problem II (大数加法)
题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...
- HDU 1002 A + B Problem II(AC代码)
#include <stdio.h> #include <string.h> #define MAX 1009 int main() { },b[MAX]={}; ,z=,r= ...
- hdu 1002 A + B Problem II【大数加法】
题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...
随机推荐
- swift---不同字体大小不同颜色label富文本设置
agreeDeal = UILabel() //富文本,不同字体颜色大小和颜色 let labelString = "登录注册,表示您同意<服务条款及隐私政策>"as ...
- lecture4-神经网络在语言上的应用
Hinton第四课 这一课主要介绍神经网络在语言处理上应用,而主要是在文本上,并附上了2003年Bengio 等人的19页的论文<A Neural Probabilistic Language ...
- Display: table-cell实现img、文字垂直居中
在文章开头先说明一下此方法的兼容性,IE8+以及其他现代浏览器都支持此属性. 直接献上一个demo吧 <!DOCTYPE html> <html> <head> & ...
- HTML5+JS 《五子飞》游戏实现(二)路线分析和资源准备
上一节 里沃特与我们分享了<五子飞>的下棋规则,可能有些伙伴看得不清楚,像我们码农还是看到代码比较靠谱.下面就把可以走棋的路线跟大家说一下. 假设从左上角开始,以0开始编号,往右数(没看第 ...
- JavaScript函数劫持
一.为什么我会写这篇文章 这篇文章其实是在一个偶然的机会下发现了居然有JavaScript劫持这种东西,虽然这种东西在平时用的比较少,而且一般实用价值不高,但是在一些特殊的情况下还是要使用到的,所以在 ...
- TextBoxFor控件的扩展---Bootstrap在mvc上的应用
TextBoxFor控件的问题: 1:自带了样式,再用bootstrap样式会有冲突. 2:要加水印,js事件,限制输入长度比较麻烦. 因此需要对textboxfor控件进行扩展. 目标: 1:能使用 ...
- nios II--实验4——按键中断软件部分
软件开发 首先,在硬件工程文件夹里面新建一个software的文件夹用于放置软件部分:打开toolsàNios II 11.0 Software Build Tools for Eclipse,需要进 ...
- Php 安装 curl
一.用好tab键.输入一部分,就按两次tab键,看看到底应该安什么
- 关于HTML+CSS设置图片居中的方法
有的时候我们会遇到这样一个问题,就是当我们按下F12进行使用firebug调试的时候,我们发现图像没有居中,页面底下有横向的滑动条出现,图片没能够居中,默认状态下只是紧靠在页面最左侧,而我们对图像缩小 ...
- php上传sae路径问题
我们写php时,会有 define('POOT_PATH', dirname(__FILE__)); 但是sea中没有用,所以我们要用 define("ROOT_PATH", $_ ...