http://acm.hdu.edu.cn/showproblem.php?pid=1002

输入的数都是正整数,比较好处理,注意进位。

//非负大整数加法

# include <stdio.h>
# include <string.h>
# define MAX 1100 int main()
{
int t;
char Num1[MAX], Num2[MAX], Num3[MAX];//Num3[] 用于保存结果 scanf("%d", &t);
for(int Count = 0; Count < t; Count++)
{
if(Count) printf("\n"); scanf("%s %s", Num1, Num2); //获取两个数字的位数
int Len1 = strlen(Num1);
int Len2 = strlen(Num2);
int Len3 = 0;
memset(Num3, '0', sizeof(Num3)); //从低位开始按位相加 先不管进位
for(int i = Len1 - 1, j = Len2 - 1; i >= 0 && j >= 0; i--, j--)
{
Num3[Len3++] = Num1[i] + Num2[j] - '0'; //如果有一个数组先为空 则把另一个数组里剩下的数字放入Num3[]
if(i == 0)
while(j--) Num3[Len3++] = Num2[j];
else if(j == 0)
while(i--) Num3[Len3++] = Num1[i];
} //处理进位
for(int i = 0; i < Len3; i++)
{
if(Num3[i] > '9')
{
Num3[i + 1] += (Num3[i] - '0') / 10;
Num3[i] = (Num3[i] - '0') % 10 + '0';
}
} //格式输出
for(int i = MAX - 1; i >= 0; i--)
{
if(Num3[i] != '0')
{
printf("Case %d:\n", Count + 1);
printf("%s + %s = ", Num1, Num2);
while(i >= 0) printf("%c",Num3[i--]);
printf("\n");
}
}
} return 0;
}

  

HDOJ-1002 A + B Problem II (非负大整数相加)的更多相关文章

  1. hdoj 1002 A + B Problem II

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. hdoj 1002 A + B Problem II【大数加法】

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. hdoj 1002 A + B Problem II 高精度 java

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. Problem : 1002 ( A + B Problem II )

    经验总结:一定要注意输出的格式,字符的空格,空行,一定要观察清楚.如本题的最后一个输出结果后面没有空行.最后代码实现的时候需要判断一下,代码如下 !=n) cout<<endl; Prob ...

  5. 抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)

    数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. while (a) //将每位数字取出来, ...

  6. HDU 1002 A + B Problem II(大整数相加)

    A + B Problem II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  7. SOJ 1002/1003/1004 大整数相加/相乘/相除

    三个题目分别考察大整数相加相乘相除运算.如果按照传统算法是取一个长数组,之后进行模拟或者FFT来进行运算.但是相对繁琐. 后来昨天的青岛区域赛网赛1001,用到了JAVA的BigDecimal,于是反 ...

  8. 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) ...

  9. hduoj 1002 A + B Problem II

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目描述如下: A + B Problem II Time Limit: 2000/1000 M ...

随机推荐

  1. 【剑指offer】面试题22:栈的压入、弹出序列

    题目: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列 ...

  2. tc令牌桶限速心得

    一.实验拓扑与实验现象 实验拓扑如图所示,在①号机上发送数据,③号机上接受数据,同时在④号机的eth1与eth2网口限制速率为115200kbps,命令如下 tc qdisc add dev eth1 ...

  3. 2.9 Model Selection and the Bias–Variance Tradeoff

    结论 模型复杂度↑Bias↓Variance↓ 例子 $y_i=f(x_i)+\epsilon_i,E(\epsilon_i)=0,Var(\epsilon_i)=\sigma^2$ 使用knn做预测 ...

  4. 【LeetCode练习题】Maximum Depth of Binary Tree

    Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...

  5. js跳转页面代码用法

    一:window.location.href='https://www.baidu.com';  需要加上http或者https,否则会查找项目内htm打开. 二:window.history.bac ...

  6. poj 3728 The merchant(LCA)

    Description There are N cities in a country, and there is one and only one simple path between each ...

  7. 浅谈ThreadPool 线程池

    本文来自:http://www.cnblogs.com/xugang/archive/2010/04/20/1716042.html 相关概念: 线程池可以看做容纳线程的容器: 一个应用程序最多只能有 ...

  8. 修改vim中的tab为4个空格

    记录一下,避免用时还得搜........ 1.临时修改 在vi中,set tabstop=4 或 set ts=4 2.永久修改 vi --version 查看要修改的文件 如果是vim的话,修改~/ ...

  9. Java - 网络编程(NetWork)

    Java - 网络编程(NetWork)   一.java.net包下的 InetAddress 类的使用:     > 一个 InetAddress 代表着一个IP地址     > 主要 ...

  10. for循环、穷举法和迭代

    循环:初始条件,循环条件,状态改变,循环体.for(初始条件;循环条件;状态改变){ 循环体}for(int i=1;i<=10;i++){ }例子:100以内与7有关的数.求100以内所有数的 ...