A + B Problem II

  Time Limit: 1000MS      Memory Limit: 65536K

Total Submissions: 16104    Accepted: 4547

Description

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input

The first line of the input contains an integer T(1

Output

For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

Sample Input

2
1 2
112233445566778899 998877665544332211

Sample Output

Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

思路:

把数值每一位拆开存进数组,利用ASCII码转换数据,然后进行相加。

#include<stdio.h>
#include<string.h>
int main()
{
    char a[1003];
    char b[1003];
    char ans[1003];
    int T;
    scanf("%d",&T);
    int cas = 0 ;
    while(T--)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(ans,0,sizeof(ans));
        scanf("%s",a);
        scanf("%s",b);
        strrev(a);
        strrev(b);
        int i;
        for(i = 0 ; a[i]&&b[i];i++)
        {
            ans[i]+=a[i]+b[i]-48;
            if(ans[i]>'9'){
            ans[i+1]++;
            ans[i]-=10;
            }
        }
        while(a[i]){
            ans[i]+=a[i];
            if(ans[i]>'9'){
            ans[i+1]++;
            ans[i]-=10;
            }
            i++;
        }
        while(b[i]){
            ans[i]+=b[i];
            if(ans[i]>'9'){
            ans[i+1]++;
            ans[i]-=10;
            }
            i++;
        }
        if(ans[i]==1)ans[i]+=48;
        strrev(ans);
        strrev(a);
        strrev(b);
        if(cas)printf("\n");
        printf("Case %d:\n",++cas);
        printf("%s + %s = %s\n",a,b,ans);
    }
}

HDU 1002 A + B Problem II的更多相关文章

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

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

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

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

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

  4. HDU 1002 - A + B Problem II - [高精度]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...

  5. hdu 1002.A + B Problem II 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 题目意思:就是大整数加法. 两年几前做的,纯粹是整理下来的. #include <stdi ...

  6. 大数加法~HDU 1002 A + B Problem II

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1002 题意: 数学题,A+B; 思路,这个数非常大,普通加法一定会超时,所以用大数加法.大数加法的基 ...

  7. HDU 1002 A + B Problem II (大数加法)

    题目链接 Problem Description I have a very simple problem for you. Given two integers A and B, your job ...

  8. HDU 1002 A + B Problem II(AC代码)

    #include <stdio.h> #include <string.h> #define MAX 1009 int main() { },b[MAX]={}; ,z=,r= ...

  9. hdu 1002 A + B Problem II【大数加法】

    题目链接>>>>>> 题目大意:手动模拟大数加法,从而进行两个大数的加法运算 #include <stdio.h> #include <strin ...

随机推荐

  1. 你真的理解 new 了吗?

    开篇先提几个问吧,如果你对这些问题都清楚了,那说明对于 new  这个关键字已经掌握得很好了,也不再需要花时间来阅读本文了, 1   new  一个class  与 new   一个Struct有什么 ...

  2. 从炉石传说的一个自杀OTK说起

    OTK就是one turn kill,不过这次我们要谈的OTK是自杀,对就是自己把自己给OTK了. 其实程序没有任何错误,只是恰巧碰上了这么个死循环. ps:文章最后有代码git地址 发动条件及效果: ...

  3. 新玩具---Amazon Kindle PaperWhite 2

    自从将闲置了一段时间的K3 Keyboard 3G送人后,就一直用Nexus7平板上装Kindle程序来读书,用着也挺好,没有出现很多人说的费眼问题,说来也奇怪上学毕业之后,一直从事编程相关的工作有七 ...

  4. Jquery-EasyUI学习2~

    下面这个Demo用的是MVC+Ado.Net.存储过程 实现功能:分页查询,添加.修改功能.模糊查询功能 先来几张效果图: 创建存储过程如下 go create proc usp_FenYe2 @se ...

  5. 访问HTML元素(节点)

    访问HTML元素等同于访问节点,能够以不同的 方式来访问HTML元素: 通过使用 getElementById() 方法 通过使用 getElementsByTagName() 方法 通过使用 get ...

  6. 在Winform中播放视频等【DotNet,C#】

    在项目中遇到过这样的问题,就是如何在Winform中播放视频.当时考察了几种方式,第一种是直接使用Windows Media Player组件,这种最简单:第二种是利用DirectX直接在窗体或者控件 ...

  7. 重新打开singleTask画面时传值问题

    记录学习之用 大家都知道假如当我们的A画面设置了android:launchMode="singleTask"时,从A画面跳到B画面之前没有finishA画面,然后在B画面使用st ...

  8. php COOKIE和SESSION的一些理解

    web服务器是基于http协议的,而http协议是无状态的,导致任意两个请求之间没有联系.但是我们登录网站后,它却能记住我们的身份,这个过程中一定使用了某个标识来区别我们的身份.对于简单数据传输的我们 ...

  9. js学习笔记6----作用域及解析机制

    1.作用域: 域:空间.范围.区域… 作用:读.写 script  全局变量,全局函数 自上而下 函数 由里到外 {} 2.js解析: ⑴   “找一些东西”:var. function. 参数…… ...

  10. PHP读取XML

    books.xml文件: 代码 <books> <book> <author>Jack Herrington</author> <title> ...