格式问题很头疼啊

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
Case2:
112233445566778899 + 998877665544332211 = 1111111111111111110

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
 int N;
 int count=1;
 scanf("%d",&N);
 getchar();
 char str1[1001],str2[1001];定义两个数组
 while(N--)
 {
  int i=0;
  int lenmax;
  int a[1001]={0},b[1001]={0},c[1001]={0};
  scanf("%s",str1);
  int len1=strlen(str1);
  for(i=0;i<len1;i++)
  {
   a[i]=str1[len1-1-i]-'0';
  }
  scanf("%s",str2);
  int len2=strlen(str2);
  for( i=0;i<len2;i++)
  {
   b[i]=str2[len2-1-i]-'0';
  }
  if(len1>=len2)
    lenmax=len1;
  else
    lenmax=len2;
  int k=0;
  for( i=0;i<lenmax;i++)
  {
   c[i]=(a[i]+b[i]+k)%10;
   k=(a[i]+b[i]+k)/10;
  }
  if(k!=0)
  {
   c[lenmax]=1;
  }
  int n=1;
  printf("Case %d:\n",count);
  count++;
  printf("%s + %s = ",str1,str2);
  if(c[lenmax]==1)
  {
   printf("1");
  }
  for( i=lenmax-1;i>=0;i--)
  {
   printf("%d",c[i]);
  }
  printf("\n");
  if(N>=1)
   printf("\n");
   
   
 }
 return 0;
}

hdu-A+B问题,大数加法的更多相关文章

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

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

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

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

  3. HDU——1715大菲波数(大数加法)

    大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  4. Hat's Fibonacci(大数加法+直接暴力)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...

  5. A + B Problem II(大数加法)

    http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/Other ...

  6. ZZNU 2125:A + B 普拉斯(傻逼题+大数加法)

    2125: A + B 普拉斯 时间限制: 1 Sec  内存限制: 128 MB 提交: 94  解决: 28 [提交] [状态] [讨论版] [命题人:admin] 题目描述 "别人总说 ...

  7. 51nod 1005 大数加法

    #include<iostream> #include<string> using namespace std; #define MAXN 10001 },b[MAXN]={} ...

  8. c#大数加法

    在C#中,我们经常需要表示整数.但是,c#的基本数据类型中,最大的long也只能表示-9,223,372,036,854,775,808 到 9,223,372,036,854,775,807之间的数 ...

  9. 玲珑杯1007-A 八进制大数加法(实现逻辑陷阱与题目套路)

    题目连接:http://www.ifrog.cc/acm/problem/1056 DESCRIPTION Two octal number integers a, b are given, and ...

  10. Leetcode 67 Add Binary 大数加法+字符串处理

    题意:两个二进制数相加,大数加法的变形 大数加法流程: 1.倒置两个大数,这一步能使所有大数对齐 2.逐位相加,同时进位 3.倒置两个大数的和作为输出 class Solution { public: ...

随机推荐

  1. iOS9适配

    一.App Transport Security xcode7安装后,你会发现ios9之后后默认所有http请求都无法继续有效,但是基于现状,我们并不能这么快改成https请求,所以基本上大多数app ...

  2. Word转换为图片PDF

    1.        Word转换为PDF,程序很多,但转换后的PDF,还可以复制,虽可以加密禁止复制,但市场上太多的PDF,还可以把PDF转换Word等其他格式,很容易被别人利用和剽窃,即便是PDF加 ...

  3. AutoInvoice in Oracle Apps R12

    AutoInvoice in Oracle Apps R12 AutoInvoice is a powerful, flexible tool you can use to import and va ...

  4. JVM笔记4:Java内存分配策略

    简单来说,对象内存分配主要是在堆中分配.但是分配的规则并不是固定的,取决于使用的收集器组合以及JVM内存相关参数的设定 以下介绍几条基本规则(使用的ParNew+Serial Old收集器组合): 一 ...

  5. Bootstrap的竞争对手Zurb Foundation

    Bootstrap并不是唯一的前端开发框架,比如还有JQuery UI.HTML5 Boilerplate等等.但对于Bootstrap来说,真正的竞争对手是Zurb Foundation.Boots ...

  6. zzzzw_在线考试系统①准备篇

    在弄完购物系统之后,小博也了解了解怎么用struts这个框架捣鼓一个在线考试系统 购物系统用的是MVC模式,现在这个struts2原理上也是基于MVC模式的.那么要做这个东西之前先了解一下难点在哪里 ...

  7. 在jsp中的css

    div#one{}div#two{ width:auto; height:20px;background-color:#FAEBD7;text-align:right;}div#three{ widt ...

  8. 关于U3D画面出现卡顿的问题

    在U3D中,曾近遇到过卡顿的问题,下面说明解决方法 一:在关于相机移动的函数中,移动的函数不应该放在Update里面应该放到LateUpdate 二:如果最开始建立项目的时候选择的时候是3D游戏,如果 ...

  9. 20160331javaweb 之JSP page 指令

  10. android studio 导入的项目有乱码-笔记2

    如果导入的项目原本就是UTF-8.且android studio编码设置为UTF-8就不会乱码.这种情况多是导入的原项目编码为GBK. 解决方法:在android studio 右下角,切换编码为GB ...