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

#include <stdio.h>
#include <string.h>
#define MAX_LEN 1000
int an1[MAX_LEN+100];
int an2[MAX_LEN+100];
char str1[MAX_LEN+100];
char str2[MAX_LEN+100];
int main()
{
 int k,N;
 scanf("%d",&N);
 for(k=1;k<=N;k++)
 {  
  int i,j,len1,len2;
  memset(an1,0,sizeof(an1));
  memset(an2,0,sizeof(an2));
  scanf("%s%s",str1,str2);
  len1=strlen(str1);
  for(j=0,i=len1-1;i>=0;i--)
  an1[j++]=str1[i]-'0';
  len2=strlen(str2);
  for(j=0,i=len2-1;i>=0;i--)
  an2[j++]=str2[i]-'0';
  for(i=0;i<MAX_LEN;i++)
  {
  an1[i]+=an2[i];
  if(an1[i]>=10)
  {
   an1[i]-=10;
   an1[i+1]++;
  }
  }
  printf("Case %d:\n",k);
  printf("%s + %s = ",str1,str2);
  for(i=MAX_LEN+100;(i>=0)&&(an1[i]==0);i--);
  if(i>=0)
  for(;i>=0;i--)
  printf("%d",an1[i]);
  else
  printf("0");
  printf("\n");
 }
 return 0;
}

hdu_1002_A+BII_bignum_201307291100

#include <stdio.h>
#include <string.h>
#define MAX_LEN 1000
int an1[MAX_LEN+100];
int an2[MAX_LEN+100];
char str1[MAX_LEN+100];
char str2[MAX_LEN+100];
int main()
{
 int k,N,t=0;
 scanf("%d",&N);
 for(k=1;k<=N;k++)
 {  
  int i,j,len1,len2;
  memset(an1,0,sizeof(an1));
  memset(an2,0,sizeof(an2));
  scanf("%s%s",str1,str2);
  len1=strlen(str1);
  for(j=0,i=len1-1;i>=0;i--)
  an1[j++]=str1[i]-'0';
  len2=strlen(str2);
  for(j=0,i=len2-1;i>=0;i--)
  an2[j++]=str2[i]-'0';
  for(i=0;i<MAX_LEN;i++)
  {
  an1[i]+=an2[i];
  if(an1[i]>=10)
  {
   an1[i]-=10;
   an1[i+1]++;
  }
  }
  printf(t++?"\nCase %d:\n":"Case %d:\n",k);
  printf("%s + %s = ",str1,str2);
  for(i=MAX_LEN+100;(i>0)&&(an1[i]==0);i--);  
  for(;i>=0;i--)
  printf("%d",an1[i]);
  printf("\n");
 }
 return 0;
}

较之上个程序有所修改,输出部分有所简化

【ACM】nyoj_103_A+BII_201307291022的更多相关文章

  1. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  2. 【ACM】HDU1008 Elevator 新手题前后不同的代码版本

    [前言] 很久没有纯粹的写写小代码,偶然想起要回炉再来,就去HDU随便选了个最基础的题,也不记得曾经AC过:最后吃惊的发现,思路完全不一样了,代码风格啥的也有不小的变化.希望是成长了一点点吧.后面定期 ...

  3. 【ACM】魔方十一题

    0. 前言打了两年的百度之星,都没进决赛.我最大的感受就是还是太弱,总结起来就是:人弱就要多做题,人傻就要多做题.题目还是按照分类做可能效果比较好,因此,就有了做几个系列的计划.这是系列中的第一个,解 ...

  4. 【ACM】那些年,我们挖(WA)过的最短路

    不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...

  5. 【ACM】不要62 (数位DP)

    题目:http://acm.acmcoder.com/showproblem.php?pid=2089 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新 ...

  6. 【Acm】八皇后问题

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...

  7. 【ACM】hud1166 敌兵布阵(线段树)

    经验: cout 特别慢 如果要求速度 全部用 printf !!! 在学习线段树 内容来自:http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/24 ...

  8. 【acm】杀人游戏(hdu2211)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2211 杀人游戏 Time Limit: 3000/1000 MS (Java/Others)    M ...

  9. 【ACM】How many prime numbers

    http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=2 #inclu ...

随机推荐

  1. PCB MS SQL SERVER版本管控工具source_safe_for_sql_server

    PCB由于业务关系复杂,业务触发一个事件时,可能需与数据库多个表进行关连处理才能拿到数据结果, 而表关连并不是简单的关连,实际是要进行大量数据筛选,逻辑判断,转换等过程...这个过程是复杂的 想一想, ...

  2. javascript之模块加载方案

    前言 主要学习一下四种模块加载规范: AMD CMD CommonJS ES6 模块 历史 前端模块化开发那点历史 require.js requirejs 为全局添加了 define 函数,你只要按 ...

  3. caffe介绍

  4. TCP/IP详解(二)

    首先,不得不吐槽一下中文版的翻译,把英文版的很多部分的删除了.中文版的pdf只有400多页,英文版有1000多页.迫于时间,只有先将就着看中文版,但是遇到不懂的地方,一定要对照英文版来看. 滑动窗口协 ...

  5. A - Petya and Strings

    Problem description Little Petya loves presents. His mum bought him two strings of the same size for ...

  6. 【Linux】VMware安装VMware Tools工具

    VMware Tools是VMware虚拟机中自带的一种增强工具,相当于VirtualBox中的增强功能(Sun VirtualBox Guest Additions),是VMware提供的增强虚拟显 ...

  7. logical vs physical address

    Logical vs physical address  1) An address generated by the CPU is a logical address. Whereas, an ad ...

  8. Matlab矩阵填充--Matlab interp2

    Matlab interp2 为Matlab的矩阵填充函数, 填充关系: x=1:11; y=1:13; x1=1:0.1:12; y1=1:0.1:14; [x2,y2]=meshgrid(x1,y ...

  9. 【sqli-labs】 less26a GET- Blind based -All you SPACES and COMMENTS belong to us -String-single quotes-Parenthesis(GET型基于盲注的去除了空格和注释的单引号括号注入)

    这个和less26差不多,空格还是用%a0代替,26过了这个也就简单了 ;%00 可以代替注释,尝试一下 order by 3 http://192.168.136.128/sqli-labs-mas ...

  10. jq 获取表单所有数据

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...