格式问题很头疼啊

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. ubuntu12.04的vim配置

    ubuntu12.04中使用的vim的版本不支持像语法高亮和文件类型检测等配置 #sudo apt-get install vim vim默认的配置使用起来还不能让人满意,还需要自己配置默认配置文件是 ...

  2. linux用户与组的管理(命令加入、手动加入、加入组、用户之间的切换)

    一.用户登录的时候须要验证的是这两个文件 检測username   Login:  root                        到该文件夹下检查 /etc/passwd 检測用passwo ...

  3. patchdiff2 函数比较插件

    https://code.google.com/archive/p/patchdiff2/downloads

  4. 摄像机(CCCamera)

  5. leecode 每日解题思路 102-Binary Tree Level Order Traversal

    題目描述: 题目链接: 102-Binary Tree Level Order Traversal 这个问题要解决的是如何逐层遍历一个二叉树,并把同一层元素放入同一list中, 再将所有元素返回. 其 ...

  6. 整理 iOS 9 适配中出现的坑

    本文主要是说一些iOS9适配中出现的坑,如果只是要单纯的了解iOS9新特性可以看瞄神的开发者所需要知道的 iOS 9 SDK 新特性.9月17日凌晨,苹果给用户推送了iOS9正式版,随着有用户陆续升级 ...

  7. 彻底理解android中的内部存储与外部存储

    我们先来考虑这样一个问题: 打开手机设置,选择应用管理,选择任意一个App,然后你会看到两个按钮,一个是清除缓存,另一个是清除数据,那么当我们点击清除缓存的时候清除的是哪里的数据?当我们点击清除数据的 ...

  8. Cygwin下安装vim后,vim中退格键无法正常使用

    问题描述: 在Cygwin中安装完vim后 进入vim,发现上下左右键和退格键都无法正常使用 问题分析: 首先考虑到的就是缺少vim的配置文件,首先查看/etc路径下是否有vim的配置文件 admin ...

  9. ActiveMQ系列(1) - 使用入门

    没网的日子真的不好过啊 1.背景:                   对于常见业务中,数据并发是一个很头疼的问题,很多时候,会出现资源共享导致线程阻塞的问题,这时候问题就来了,,,老板也尾随来了,来 ...

  10. WildFly 9.0.2+mod_cluster-1.3.1 集群配置

    一.配置背景 最近使用WildFly 9.0.2作为中间件开发系统,给客户不熟的时候需要使用集群来进行负载均衡,一开始想到是使用Nginx.但是只通过Nginx使用 ip_hash 模式没有做到ses ...