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. MATLAB调用C程序、调试和LDPC译码

    MATLAB是一个很好用的工具.利用MATLAB脚本进行科学计算也特别方便快捷.但是代码存在较多循环时,MATLAB运行速度极慢.如果不想放弃MATLAB中大量方便使用的库,又希望代码能迅速快捷的运行 ...

  2. 深入理解OOP(二):多态和继承(继承)

    本文是深入浅出OOP第二篇,主要说说继承的话题. 深入理解OOP(一):多态和继承(初期绑定和编译时多态) 深入理解OOP(二):多态和继承(继承) 深入理解OOP(三):多态和继承(动态绑定和运行时 ...

  3. Java序列化中的SerialVersionUid

    版权声明:本文为博主fbysss原创文章,转载请注明出处 作者:fbysssmsn:jameslastchina@hotmail.com  blog:blog.csdn.NET/fbysss声明:本文 ...

  4. Eclipse利用Maven2搭建SpringMVC框架的Web工程

    一.准备工作: 下载apache-maven--> 配置Maven_home -->下载Eclipse Maven插件 二.新建工程:   选择新建Maven Project  arche ...

  5. setTimeout和setinterval的区别

    setTimeout("alert('久等了')",2000)是等待多长时间开始执行函数 setinterval(fn,1000)是每隔多长时间执行一次函数 setTimeout和 ...

  6. Service之来电监听(失败的案例)

    Service:服务,可以理解成一个运行再后台没有界面的Activity,集成于Seriver,是四大组件之一 Service的继承关系:Service-->ContextWrapper--&g ...

  7. SharePoint 2013 本地开发解决方案以及远程调试

    转自:http://www.cnblogs.com/jianyus/p/3523387.html 在SharePoint开发中,我们需要在部署有SharePoint环境的服务器中开发,这是一件让人很苦 ...

  8. Windows配置mycat

    MyCat使用Mysql的通讯协议模拟成一个MySQl服务器,并建立了完整的Schema(数据库).Table(数据表).User(用户)的逻辑模型,并将这套逻辑模型映射到后端的存储节点DataNod ...

  9. Boundary Following Algorithm

    又一个精妙的算法. 输入: 组成一个region, 或者它的boundary的点集\(P\) 输出: 这个region 顺时针(或相反)的有序排列的边界点. 算法详细: 见图. 详见 DIP 11.1 ...

  10. 【ASP.NET Identity系列教程(一)】ASP.NET Identity入门

    注:本文是[ASP.NET Identity系列教程]的第一篇.本系列教程详细.完整.深入地介绍了微软的ASP.NET Identity技术,描述了如何运用ASP.NET Identity实现应用程序 ...