Problem 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<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
 
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
 
 
简单题:大数的运算

注意格式(Case的首字母大写、各种空格、每一行之间有空行,最后一行没有空行)!

给出几组测试数据:

6

1 2
1 0
9999 1
1 999999
5555 4445
112233445566778899 998877665544332211
 
java code:
import java.util.*;
import java.io.*;
import java.math.*; class Main
{
public static BigInteger plus(BigInteger a, BigInteger b) {
BigInteger c;
c = a.add(b);
return c;
} public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
int T, i;
BigInteger a,b;
T = cin.nextInt();
i = 1;
while((T--) > 0) {
a = cin.nextBigInteger();
b = cin.nextBigInteger();
System.out.println("Case "+ i +":");
System.out.println(a + " + "+ b + " = "+ plus(a, b));
i++;
if(T > 0)
System.out.println();
}
}
}

C code

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void solve()
{
int n,i,j,k,flag,t,cas,L;
char a[],b[],c[];
scanf("%d",&n);
getchar();
cas=;
while(n--)
{
flag=;
memset(a,'\0',sizeof(a));
memset(b,'\0',sizeof(b));
memset(c,'\0',sizeof(c));
scanf("%s",a);
scanf("%s",b);
printf("Case %d:\n",cas);
printf("%s",a);
printf(" + ");
printf("%s",b);
printf(" = ");
strrev(a);
strrev(b);
k=i=;
L=(strlen(a)>strlen(b)?strlen(b):strlen(a));
while(i<L)
{
t=(a[i]-'')+(b[i]-'')+flag;
flag=(t>=?:);
c[k++]=t%+'';
i++;
}
if(a[i]=='\0')
{
while(b[i]!='\0') {
t=b[i++]-''+flag;
c[k++]=t%+'';
flag=(t>=?:);
}
}
else
{
while(a[i]!='\0') {
t=a[i++]-''+flag;
c[k++]=t%+'';
flag=(t>=?:);
}
}
if(flag) c[k]='';
else k--;
while(k>=)
{
printf("%c",c[k]);
k--;
}
printf("\n");
if(n>) printf("\n");
cas++;
}
} int main()
{
solve();
return ;
}

hdoj1002--A + B Problem II的更多相关文章

  1. HDOJ-1002 A + B Problem II (非负大整数相加)

    http://acm.hdu.edu.cn/showproblem.php?pid=1002 输入的数都是正整数,比较好处理,注意进位. //非负大整数加法 # include <stdio.h ...

  2. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  3. nyoj 623 A*B Problem II(矩阵)

    A*B Problem II 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大 ...

  4. HDU 1002 A + B Problem II

    A + B Problem II   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted ...

  5. A + B Problem II

    之前总是在查阅别人的文档,看着其他人的博客,自己心里总有一份冲动,想记录一下自己学习的经历.学习算法有一段时间了,于是想从算法开始自己的博客生涯O(∩_∩)O~~ 今天在网上看了一道大数相加(高精度) ...

  6. nyoj 103 A + B problem II

    点击打开链接 A+B Problem II 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 I have a very simple problem for you. G ...

  7. hdu 1023 Train Problem II

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1212 Train Problem II Description As we all know the ...

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

  9. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  10. hdoj 1002 A + B Problem II

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

随机推荐

  1. 【BZOJ2870】最长道路tree 点分治+树状数组

    [BZOJ2870]最长道路tree Description H城很大,有N个路口(从1到N编号),路口之间有N-1边,使得任意两个路口都能互相到达,这些道路的长度我们视作一样.每个路口都有很多车辆来 ...

  2. css,查询相应标签,div等

    1.类名 .类别 例子: 查询类名为“useradd” .useradd{ margin-top:50px; margin-left:200px;} 2.属性找 例子:查询类为useradd下的inp ...

  3. 《UNIX网络编程》 -- 第五章

    str_cli 和 str_echo 函数 需要先弄清楚 3.9 readn.writen 和 readline 函数 str_cli void str_cli(FILE *fp, int sockf ...

  4. mustache模板技术(转)

    项目首页:http://mustache.github.com/  项目文档:http://mustache.github.com/mustache.5.html  Demo:  http://mus ...

  5. Vue.js之组件嵌套小demo

    Vue.js之组件嵌套的小demo项目 第一步:初始化一个wabpack项目,这里不在复述.第二步:在components文件夹下新建Header.vue Footer.vue和Users.vue三个 ...

  6. [IOI2018]狼人

    [IOI2018]狼人 luogu UOJ 对人形和狼形分别建克鲁斯卡尔重构树 每次询问就是对于两棵树dfs序的一个二维数点,主席树维护 #include<bits/stdc++.h> u ...

  7. CF85D Sum of Medians

    CF85D Sum of Medians 题意翻译 一个集合,初始为空.现有三个操作: 1.add:向集合里加入数x,保证加入前集合中没有数x: 2.del:从集合中删除数x,保证删除前集合中有x: ...

  8. ThreadLocal(四) : FastThreadLocal原理

    一.ThreadLocal的原理以及存在的问题 a. 每个线程内部维护了一个ThreadLocal.ThreadLocalMap类型的变量 b. ThreadLocalMap 的 key 为 Thre ...

  9. Spring 单例

    我们知道 Web 容器本身就是多线程的,Web 容器为一个 Http 请求创建一个独立的线程,所以由此请求所牵涉到的 Spring 容器中的 Bean 也是运行于多线程的环境下.在绝大多数情况下,Sp ...

  10. 解决\build\outputs\apk\dream-debug.apk does not exist on disk错误

    \build\outputs\apk\dream-debug.apk does not exist on disk.错误,apk一直装不到手机里. 最有效的解决方法:Build>Buid APK