hdu 1002 A + B Problem II(大正整数相加)
代码:
#include<cstdio>
#include<cstring>
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std; char s1[10000],s2[10000],s3[10000]; int main()
{
int t;
scanf("%d",&t);
int tt=0;
while(t--)
{
++tt;
if(tt!=1)
printf("\n");
scanf("%s%s",s1,s2);
int len1,len2,len3;
len1=strlen(s1);
len2=strlen(s2);
len3=Min(len1,len2);
int k=0;
int i=len1-1;
int j=len2-1;
int pos=0;
while(len3--)
{
int temp=(s1[i--]-'0'+s2[j--]-'0'+k);
s3[pos++]=(temp%10+'0');
k=temp/10;
}
if(i==-1&&j==-1)
{
if(k!=0)
s3[pos++]=k+'0';
}
else if(i==-1&&j!=-1)
{ while(j>=0)
{
int temp=s2[j--]-'0'+k;
s3[pos++]=(temp%10+'0');
k=temp/10;
}
if(k!=0)
s3[pos++]=k+'0';
}
else
{
while(i>=0)
{
int temp=s1[i--]-'0'+k;
s3[pos++]=(temp%10+'0');
k=temp/10;
}
if(k!=0)
s3[pos++]=k+'0';
}
printf("Case %d:\n",tt);
printf("%s + %s = ",s1,s2);
for(i=pos-1;i>=0;i--)
{
printf("%c",s3[i]);
}
printf("\n");
}
return 0;
}
hdu 1002 A + B Problem II(大正整数相加)的更多相关文章
- 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)
数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...
- 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(高精度加法(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 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...
- HDU 1002 A + B Problem II
A + B Problem II Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16104 Accepted ...
- 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 题意: 数学题,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= ...
随机推荐
- php 制作略缩图
一.需求 最近公司的项目中有个需求,就是用户上传自己的微信二维码,然后系统会自动将用户的微信二维码合并到产品中 二.分析 因为该系统是手机端的,所以从用户端的体验出发,用户当然是直接在微信上保存二维码 ...
- 模拟Queue(wait/notify)
BlockingQueue:顾名思义,首先它是一个队列,并且支持阻塞的机制,阻塞的放入和得到数据.我们要实现LinkedBlockingQueue下面的两个方法put和take. put(anObje ...
- 【Oracle】truncate分区表
分区表是生产中常用的一种表,它可以实现数据的按类存放,极大的提高了数据的查询及维护.当我们不需要某一分区的数据时,可以采用truncate来清空分区.实验如下: SQL)) partition by ...
- C语言笔记(一)
笑话一枚:程序员 A:“哥们儿,最近手头紧,借点钱?”程序员 B:“成啊,要多少?”程序员 A:“一千行不?”程序员 B:“咱俩谁跟谁!给你凑个整,1024,拿去吧.” =============== ...
- Assembly之instruction之CMP
CMP[.W] Compare source and destinationCMP.B Compare source and destination Syntax CMP src,dst or ...
- 如何在编辑器打开Java程序
我们都知道运行JAVA文件,可以从软件控制台运行我们写好的java文件,也可以从windows窗口运行,我们最开始接触的是通过windows窗口来运行java文件,下面简单介绍一下如何如何在编辑器打开 ...
- 安卓使用JNI-NDK
详细配置,参考链接:http://www.jb51.net/softjc/115204.html 一 .为什么使用NDK 1.代码的保护.由于apk的java层代码很容易被反编译,而C/C++库反汇 ...
- maven多个子项目、父项目之间的引用问题
在项目时用到maven管理项目,在一个就项目的基础上开发新的项目:关于子项目和父项目,子项目与子项目之间的调用问题,发现自己存在不足,以下是自己查询的问题,解决了自己的疑惑. 问题 下面是一个简略的项 ...
- Git及Github环境搭建(Windows系统)
一.github账号注册 1.打开网址https://github.com 注册账号: 二.本地安装Git 1.安装包下载地址:链接:https://pan.baidu.com/s/1smpnJL7 ...
- Jsp页面中常用的EL表达式
首先引入标签 <%@ page language="java" contentType="text/html; charset=utf-8" pageE ...