HDU1002 A + B Problem II 大数问题
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1002
A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 409136 Accepted Submission(s): 79277
1 2
112233445566778899 998877665544332211
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
#include<bits/stdc++.h>
int main()
{
int n;
scanf("%d",&n);
int y=;
while(y<=n)
{
char a[]= {''},b[]= {''},C[],A[],B[];
getchar();
scanf("%s %s",a,b);
int l1=strlen(a);
int l2=strlen(b);
if(l1>l2)
{
int k=l1-l2;
char d[k];
for(int i=; i<k; i++)
d[i]='';
d[k]='\0';
B[]='\0';
strcat(B,d);
strcat(B,b);
A[]='\0';
strcat(A,a);
}
else if(l1<l2)
{
int k=l2-l1;
char d[k];
for(int i=; i<k; i++)
d[i]='';
d[k]='\0';
A[]='\0';
strcat(A,d);
strcat(A,a);
B[]='\0';
strcat(B,b);
}
else if(l2==l1)
{
A[]='\0';
B[]='\0';
strcat(A,a);
strcat(B,b);
}
l1=strlen(A);
l2=strlen(B);
int k=,cc=;
for(int i=l1-,j=l2-; i>=&&j>=; i--,j--)
{
int t=A[i]-''+B[j]-''+cc;
if(t>=)
{
cc=;
t=t-;
}
else
{
cc=;
}
C[k]=t+'';
k++;
}
if(cc==)
{
C[k]='';
C[k+]='\0';
}
else
{
C[k]='\0';
}
int l3=strlen(C);
printf("Case %d:\n",y);
printf("%s + %s = ",a,b);
for(int i=l3-; i>=; i--)
{
printf("%c",C[i]);
}
printf("\n");
if(y!=n)
printf("\n");
y++;
}
return ;
}
HDU1002 A + B Problem II 大数问题的更多相关文章
- hdu1002 A + B Problem II(大数题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/ ...
- 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) ...
- hdu1002 A + B Problem II[大数加法]
目录 题目地址 题干 代码和解释 参考 题目地址 hdu1002 题干 代码和解释 由题意这是一个涉及到大数的加法问题.去看了一眼大数加法的方法感觉头很大,然后突然发现Java可以流氓解决大数问题,毅 ...
- 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过
杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...
- hdu1002 A + B Problem II(高精度加法) 2016-05-19 12:00 106人阅读 评论(0) 收藏
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- [HDU1002] A + B Problem II
Problem Description I have a very simple problem for you. Given two integers A and B, your job is to ...
- A + B Problem II 大数加法
题目描述: Input The first line of the input contains an integer T(1<=T<=20) which means the number ...
- A + B Problem II(大数加法)
一直格式错误,不想改了,没A #include <iostream> #include <stdio.h> #include <string.h> #include ...
- HDU 1023 Train Problem II 大数打表Catalan数
一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n ...
随机推荐
- 转:javascript时间戳和日期字符串相互转换
转:javascript时间戳和日期字符串相互转换 <html xmlns="http://www.w3.org/1999/xhtml"> <head> & ...
- CSS样式之a标签(原文网址http://www.divcss5.com/shili/s57.shtml)
这是个人在做网站的时候整理的关于a标签的使用方法,整理一下,方便下次使用. 一.a超链接的代码 <a href="http://www.baidu.com" target=& ...
- css动画笔记
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ios 下拉列表
#import <UIKit/UIKit.h> @class FVPullDownMenu; /** 指示器状态*/ typedef enum { IndicatorStateShow = ...
- Windows access Linux / Ubuntu via Remote Desktop via xrdp
Windows 多用户远程桌面连接到 Ubuntu / Linux Access Ubuntu from Windows remotely Follow these steps : Step 1 ...
- PHP根据秒计算持续时长
/** * 计算持续时长 * * @param int $second 秒数 * @return string $duration 5天10小时43分钟40秒 */ function second2d ...
- logback总结
Logback Logback由三大模块组成:logback-core.logback- classic和logback-access. Logback-core是其它两个模块的基础模块. Logba ...
- selenium&phantomjs实战--漫话爬取
为什么直接保存当前网页,而不是找到所有漫话链接,再有针对性的保存图片? 因为防盗链的原因,当直接保存漫话链接图片时,只能保存到防盗链的图片. #!/usr/bin/env python # _*_ c ...
- MVC $.Ajax()+Json实现数据库访问并显示数据
我们在使用搜索引擎时经常会看到这样一个效果 在输出输入相关文字时会有与之对应的相关提醒,作为一个MVC初学者我也做了一个简单版的“搜索工具”,分享给初学mvc和ajax的童鞋(各位大神勿喷),也加深我 ...
- VVeboImageView
VVeboImageView https://github.com/johnil/VVeboImageView A UIImageView to play gif with low memory. 一 ...