点击打开链接

A+B Problem II

时间限制:3000 ms  |  内存限制:65535 KB
难度:3
描述

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

A,B must be positive.

输入
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.
输出
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.
样例输入
2
1 2
112233445566778899 998877665544332211
样例输出
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

大数加法,以前写的,可读性很差,唯一有用的地方是reverse函数,用来逆置一个字符串

#include<string.h>
#include<stdio.h>
#include<iostream>
#include <algorithm>
using namespace std;
char str[2][1002];
int main(){
int len[2];
int num;
bool flag;
int i , j;
scanf("%d", &num);
for(j= 1; j <=num; j++) {
memset(str, 0, sizeof(str));
scanf("%s %s", str[0], str[1]);
printf("Case %d:\n", j);
printf("%s + %s = " , str[0] , str[1]);
len[0] = strlen(str[0]);
len[1] = strlen(str[1]);
reverse(str[0], str[0] + len[0]);
reverse(str[1], str[1] + len[1]);
if(len[0] > len[1]) flag = 0;
else flag = 1;
for(i= 0 ; str[!flag][i]; i++){
str[flag][i] += str[!flag][i] - '0';
}
for(i = 0 ;str[flag][i]; i++){
if(str[flag][i] > '9'){
if(str[flag][i + 1] < '0')
str[flag][i + 1] = '1';
else
str[flag][i + 1] ++;
str[flag][i] -= 10;
}
}
len[flag] = strlen(str[flag]);
reverse(str[flag], str[flag] + len[flag]);
printf("%s\n" , str[flag]);
}
return 0;
}

nyoj 103 A + B problem II的更多相关文章

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

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

  2. nyoj 103-A+B Problem II (python 大数相加)

    103-A+B Problem II 内存限制:64MB 时间限制:3000ms 特判: No 通过数:10 提交数:45 难度:3 题目描述: I have a very simple proble ...

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

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

  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. hdu 1023 Train Problem II

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

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

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

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

  9. 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. 【转】PHP 之 CURL 模拟登陆并获取数据

    1.CURL模拟登陆的流程和步骤2.tempnam 创建一个临时文件3.使用CURL模拟登陆到PHP100论坛 <?php$cookie_file = tempnam('./temp','coo ...

  2. python分割数组里面重复的元素

    c=[1,1,1,1,2,2,2,3,3,4,4,4,4,4,5,5,5,] a = [] x = [] for i in range(0,len(c)): if i + 1 < len(c): ...

  3. php编译安装参数说明

    http://www.cnblogs.com/52php/p/5668828.html

  4. 详解@Autowired、@Qualifier和@Required

    A.@Autowired org.springframework.beans.factory.annotation.Autowired public @interface Autowired Mark ...

  5. .NET RSACryptoServiceProvider PEM + DER Support

    http://www.christian-etter.de/?p=771 In .NET, RSACryptoServiceProvider greatly simplifies common tas ...

  6. ios外包公司——技术分享:IOS开发教程

        iOS入门培训,适合已经有C/C++/Java/C#基础的人学习.   本大仙主讲,总共4讲(第4讲尚在制作中),这仅仅是iOS开发的入门而已.学完本教程,应该已经足够你自学并开发app了. ...

  7. C#.NET ,微信退款证书

    微信退款时遇到:基础连接已经关闭 连接被意外关闭. 服务器环境:WIN SERVER 2008 R2.  WINDOWS服务承载的WCF服务,基于.NET FRAMEWORK 3.5. 第一笔交易的退 ...

  8. bzoj3545: [ONTAK2010]Peaks

    Description 在Bytemountains有N座山峰,每座山峰有他的高度h_i.有些山峰之间有双向道路相连,共M条路径,每条路径有一个困难值,这个值越大表示越难走,现在有Q组询问,每组询问询 ...

  9. Linux下高并发socket最大连接数所受的各种限制

    http://blog.csdn.net/guowake/article/details/6615728 1.修改用户进程可打开文件数限制 在Linux平台上,无论编写客户端程序还是服务端程序,在进行 ...

  10. 二. log4j配置文件

    log4j的配置文件 # Output pattern : date [thread] priority category - message log4j.rootLogger=info,Consol ...