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 ...
随机推荐
- PHP的一个牛逼的数组排序函数array_multisort
函数详情,具体可参考 官方手册 array_multisort 实际问题是这样的,有这么一组数据: $arr_times = array( array('2018-04-12 04:25:00', 3 ...
- 初学PS
PS中的一些快捷键:新建:Ctrl+N 放大:Ctrl++ 缩小:Ctrl+- 首选项:Ctrl+K 标尺:Ctrl+R移动视图:空格键 绘制正圆:Shift 绘制鼠标落脚点为中心的正圆:Shift+ ...
- springboot学习入门之一---基本了解
1springboot基本了解 1.1概述 Spring Boot不是一门新技术,本质上就是spring. 特性: 1) 零配置(或很少配置) 2) 四个核心:(ASCA) 3.1)自动配置:spri ...
- [EXCEL] 不能清除剪贴板: We couldn't free up space on the clipboard. Another program might be using it right now
Excel复制粘贴时出现以下错误,原因是有程序占用了剪切板. We couldn't free up space on the clipboard. Another program might be ...
- 更新tableView的某个cell
更新tableView的某个cell 异步加载完数据后更新某个cell,这应该是非常常见的使用方法了,我们经常会用reloadData. 效果: 源码: // // RootViewControlle ...
- 使用CADisplayLink写秒表
使用CADisplayLink写秒表 效果: 源码: StopWatch.h 与 StopWatch.m // // StopWatch.h // ShowTime // // Created by ...
- 使用keychain永久存储数据
使用keychain永久存储数据 https://github.com/soffes/sskeychain keychain当然还是使用开源的好:),keychain是干啥用的?这个,baidu一下你 ...
- 使用YXHUD
使用YXHUD 这是本人自己设计的一个类,但功能很不完善,先看看效果: 源码: YXHUD.h 与 YXHUD.m // // YXHUD.h // UILabel // // Created by ...
- AC自动机, 字符串匹配算法
package utils import java.util.HashMapimport java.util.LinkedListimport util.control.Breaks._import ...
- docker 自制CentOS 6-lnp镜像
环境准备 1台centos 6.5镜像虚拟机 febootstrap.docker febootstrap 安装 yum install -y yum-priorities && r ...