Description

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

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 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
 
 
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string.h>
using namespace std;
int f(char a[],char b[],int s[])
{
int m=strlen(a),n=strlen(b),i,x[],y[],k;
memset(x,,sizeof(x));
memset(y,,sizeof(y));
k=max(m,n);
if(m==k){
for(i=;i<m;i++)x[i]=a[i]-'';
for(i=m-;i>=m-n;i--)y[i]=b[n-m+i]-'';
}
if(n==k){
for(i=;i<n;i++)y[i]=b[i]-'';
for(i=n-;i>=n-m;i--)x[i]=a[m-n+i]-'';
}
s[]=;
for(i=;i<k+;i++)s[i]=x[i-]+y[i-];
for(i=k;i>=;i--){
if(s[i]>){
s[i]-=;
s[i-]++;
}
}
return k;
}
int main()
{
char a[],b[];
int n,k=;
cin>>n;
while(k<=n){
cin>>a>>b;
cout<<"Case "<<k<<":"<<endl;
cout<<a<<" + "<<b<<" = ";
int s[];
int t=f(a,b,s);
for(int i=;i<t+;i++){
if(s[]==&&i==)continue;
cout<<s[i];
}
if(k!=n)cout<<endl;
cout<<endl;
k++;
}
//system("pause");
return ;
}

格式错误好几次

J - A + B Problem II(第二季水)的更多相关文章

  1. F - The Fun Number System(第二季水)

    Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...

  2. D - Counterfeit Dollar(第二季水)

    Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...

  3. A - 高精度(大数)N次方(第二季水)

    Description Problems involving the computation of exact values of very large magnitude and precision ...

  4. Y - Design T-Shirt(第二季水)

    Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...

  5. N - Robot Motion(第二季水)

    Description A robot has been programmed to follow the instructions in its path. Instructions for the ...

  6. S - 骨牌铺方格(第二季水)

    Description          在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.         例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...

  7. R - 一只小蜜蜂...(第二季水)

    Description          有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数.         其中,蜂房的结构如下所示.     ...

  8. E - Number Sequence(第二季水)

    Description A single positive integer i is given. Write a program to find the digit located in the p ...

  9. I - Long Distance Racing(第二季水)

    Description Bessie is training for her next race by running on a path that includes hills so that sh ...

随机推荐

  1. iOS开发 ~应用程序设计理念:视图控制器(UIViewController)、视图(UIView)

    应用程序设计理念:视图控制器(UIViewController).视图(UIView) 利用视图控制器(底层)管理视图(外观),一对一 1.视图的作用:负责显示的外观 2.视图控制器的作用:创建界面. ...

  2. swift——设置navigationitemtitle的内容以及格颜色

    1.用UILabel,自定义整个titleview // var TitleText = UILabel() self.TitleText.frame = CGRectMake(0, 0, 100, ...

  3. activiti笔记二:用户任务

    1, assignee 代替humanPerformer  功能 2, cadidateUsers代替potentialOwner功能 3, candidateGroups代替potentialOwn ...

  4. [原]C++关于运算符重载的程序报错error…

    错误信息如下: 1>t2.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Date::Date(void)" (??0D ...

  5. oc语言--面向对象的三大特性

    一.封装 1.什么是封装 在程序上,隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读和修改的访问级别:将对象得到的数据和行为(或功能)相结合,形成一个有机的整体,也就是将数据与操作数据的 ...

  6. VS2012 的MVC4实例

    原文链接:http://wenku.baidu.com/link?url=nkq-UZd-Ui83Nuoh66n4KqdwK4V_zzKqakmmG6VBgq2BfWlMiPhz1JXN9R3CWxN ...

  7. Taglib、EL、OGNL

    Taglib.EL.OGNL 阅读目录 1. Taglib(tag library) 标签库 2. EL(Expression Language) 表达式 3. OGNL(Object-Graph N ...

  8. typedef函数指针那些事

    首先来介绍下函数指针: 函数指针是指向函数的指针变量,即本质是一个指针变量. int (*f) (int x); /* 声明一个函数指针 */ f=func; /* 将func函数的首地址赋给指针f ...

  9. WPF 资源收集

    转载地址:http://www.cnblogs.com/zhoujg/archive/2009/11/04/1596195.html OpenExpressApp的UI现在是使用WPF,所以熟悉WPF ...

  10. 夏宇闻教授谈FPGA工程师的入门学习

    1. 必须清楚自己究竟适合不适合做工程师. 看看自己的性格特点,是不是特别安静,又耐得住寂寞.因为FPGA工程师是一个辛苦的工作,不但要通过不断学习研究提升自己的设计水平,还要经常性的熬夜加班敲写代码 ...