格式问题很头疼啊

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

    private    { Private declarations }    procedure WMMOVE(var Msg: TMessage); message WM_MOVE;  proced ...

  2. Vim 快捷键整理

    一.移动光标 1.左移h.右移l.下移j.上移k 2.向下翻页ctrl + f,向上翻页ctrl + b 3.向下翻半页ctrl + d,向上翻半页ctrl + u 4.移动到行尾$,移动到行首0(数 ...

  3. Linux crontab 命令格式与具体样例

    基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...

  4. 硬菜点播台 | MySQL阿里实践经典案例之参数调优最佳实践

    http://mp.weixin.qq.com/s?__biz=MzA4NjI4MzM4MQ%3D%3D&mid=512708319&idx=1&sn=6af5f424d7cd ...

  5. 释放Linux磁盘空间的一种方法

        1.用df 检查发现/根目录可用空间为0   [root@/]#df -h   2.用du检查发现 各目录占用的空间都很少,有约3G的空间莫名其妙地丢了.   [root@/]# du -m ...

  6. linux shell read command-Getting User Input Via Keyboard--ref

    ref:http://bash.cyberciti.biz/guide/Getting_User_Input_Via_Keyboard You can accept input from the ke ...

  7. iOS之核心动画(Core Animation)

      Core Animation,中文翻译为核心动画,它是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍.也就是说,使用少量的代码就可以实现非常强大的功能. Core ...

  8. java strtus2 DynamicMethodInvocation配置(二)

    前面一章讲了下动态配置的方法.那样,能够直接动态的调用action里面的方法, 这里展示一种配置更少,更简洁的一种方法. 在前一章其他不变的情况下,改变配置文件 <package name=&q ...

  9. Eclipse搭建服务器

    一.首先,依次点击Window -->preferences-->Server-->Runtime environment -->add,再选择Apache,选择TOMcat的 ...

  10. 多个线程访问url

    多个线程访问url package com.aig.ecompassios.ecard; import java.io.BufferedReader; import java.io.InputStre ...