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 ...
随机推荐
- CSS中vertical-align的默认值baseline的理解
写在前面的话 在学校业余学习了一个月的CSS,人生中第一篇博客就献给CSS了,欢迎大家指正文章中不正确的地方,在此感谢.在尝试开始写博客的时候查了好多资料,原本以为写自己熟悉的知识的博客很容易,没想到 ...
- java获取本月第一天和最后一天
public class CalendarTest { public static void main(String[] args) { // 获取当前年份.月份.日期 Calendar cale = ...
- 行动学习方法----PARR
- java 内存分析之方法返回值二
package Demo; class Point { private double x, y; public Point(double x, double y) { this.x = x; this ...
- Angular1.x DirtyChecking(脏值检查) $watch, $apply, $digest
Dirty Checking (脏值检查) Digest cycle and $scope Digest cycle and $scope First and foremost, AngularJS ...
- 【Java】【转】在命令行中编译和运行java
原文:http://blog.csdn.net/u010900574/article/details/50792353 同时加载编译多个jar包和java文件 在个人平常使用或者当我们把代码部署到Li ...
- 使用 NGINX 进行微程序缓存的好处
[编者按]本文作者为 Owen Garrett,主要介绍使用 nginx 进行微程序缓存的好处,辅之以生动的实例.文章系国内 ITOM 管理平台 OneAPM 编译呈现. NGINX 和 NGINX ...
- 关于 ExpressRoute 的虚拟网络网关
虚拟网络网关用于在 Azure 虚拟网络和本地位置之间发送网络流量. 配置 ExpressRoute 连接时,必须创建并配置虚拟网络网关和虚拟网络网关连接. 创建虚拟网络网关时,需要指定几项设置. 其 ...
- Vue2学习笔记:事件对象、事件冒泡、默认行为
1.事情对象 <!DOCTYPE html> <html> <head> <title></title> <meta charset= ...
- Sql Server中的谓词和运算符
谓词和运算符配合使用是我们得到理想数据的最佳途径. 一.浅谈谓词 谓词的概念:一个运算结果为True.False或Unknown的逻辑表达式.它的运用范围有:where子句.Having子句.Chec ...