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. 【Nutch2.2.1基础教程之2.2】集成Nutch/Hbase/Solr构建搜索引擎之二:内容分析

    请先参见"集成Nutch/Hbase/Solr构建搜索引擎之一:安装及运行",搭建测试环境 http://blog.csdn.net/jediael_lu/article/deta ...

  2. Lucene学习总结之七:Lucene搜索过程解析

    一.Lucene搜索过程总论 搜索的过程总的来说就是将词典及倒排表信息从索引中读出来,根据用户输入的查询语句合并倒排表,得到结果文档集并对文档进行打分的过程. 其可用如下图示: 总共包括以下几个过程: ...

  3. SQL实现递归及存储过程中In()参数传递解决方案[转]

    SQL实现递归及存储过程中In()参数传递解决方案   1.SQL递归 在SQL Server中,我们可以利用表表达式来实现递归算法,一般用于阻止机构的加载及相关性处理.   -->实现: 假设 ...

  4. 实现js浮点数加、减、乘、除的精确计算(网上很多文章里的方法是不能解决所有js浮点数计算误差的)

    最近做项目,要用到js的加.减.乘.除的计算,发现js浮点数计算会有一些误差. 网上有很多文章都有js浮点数计算误差的解决方法,说能解决这个问题,But…….比如一个加法函数,如下: function ...

  5. uWSGI

    参考:http://perlmaven.com/deploying-pyton-with-uwsgi-on-ubuntu-13-10

  6. 垃圾回收GC——JVM之七

    垃圾回收是个复杂的过程: 请以此阅读下列文章: 垃圾回收1:http://blog.csdn.net/sun305355024sun/article/details/41394729 垃圾回收2:ht ...

  7. QTableView使用HTML显示富文本

    对于QTableView中的显示,我们前面介绍过很多种,其中包括:文本.进度条.复选框等,今天我们介绍一下关于富文本的显示. 可能绝大多数小伙伴会通过QAbstractTableModel中的data ...

  8. zend server 和zend studio安装

    zend server安装完后需要更改一个xml文件. 用记事本打开D:\Program Files\Zend\ZendServer\etc\ZendEnablerConf.xml文件. 将 锘??x ...

  9. STL中,迭代器的分类

    五类迭代器如下: 1.输入迭代器:只读,一次传递    为输入迭代器预定义实现只有istream_iterator和istreambuf_iterator,用于从一个输入流istream中读取.一个输 ...

  10. postgresql基本语句

    preface,熟悉pgsql sql Language article disorder; 1,pgsql数据库控制台Cli(command line interface) help mannual ...