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. ibatis复用SQL片段、引入片段 动态条件增加

    1:ibatis复用SQL片段.引入片段  使用[sql]和[include]标签: 通常情况下,你会这样写:xml 代码 <select id="selectItemCount&qu ...

  2. 修改 “嗨加游-Prefix.pch” 或者 “嗨加游-Info.plist ” 方法

    如果要更改Info.plist与Prefix.pch文件实际路径,也就是实际文件的位置(不是在工程中的组织路径),需要到Build Settings中修改对应的配置,不然工程就找不到对应的Info.p ...

  3. _BLOCK_TYPE_IS_VALID错误

    _BLOCK_TYPE_IS_VALID宏用来检测这个内存块在当前堆上是否有效,但是这里的指针是一个临时变量,临时变量是在栈上分配的,函数清理栈时会自动回收这些内存,程序员无需管理. new 和 ma ...

  4. uva 10763 Foreign Exchange <"map" ,vector>

    Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enthu ...

  5. java中的IO流读取文件

    1 InputStream类和OutputStream类 InputStream.read()方法从文件中读取一个字节(0-255),然后将此字节转换成对应的整数返回.假设一个文件的编码为utf-8编 ...

  6. C# String 与 byte 互转

    String转换为byte数组用byte[] arr = System.Text.Encoding.Default.GetBytes("abcde") byte数组转换为Strin ...

  7. CSS布局部分知识总结

    一 切图 通过一个周的切图练习,我发现只有亲自动手后才能通过问题不断加深技术,要熟练掌握HTML页面编写时候时PHOTOSHOP操作. 以下一些知识点在网络布局时也是很重要的. 1.ul标签在谷歌.火 ...

  8. C编译环境的搭建-sublime篇

    1.安装sublime text 2.下载MingW: http://sourceforge.net/projects/mingw-w64/?source=typ_redirect 3.sublime ...

  9. bat加载和分离VHD

    VHD: vhd:虚拟磁盘格式 [详看 百科 ] 应用: 建立VHD文件,把系统装进VHD,然后从VHD启动. 优点: 因为系统在一个文件里,所以有可删,可移动,可快照的优点. VHD装系统方法: 请 ...

  10. information_schema.engines学习

    当前mysql实例的存储引擎信息可以从information_schema.engines 中查询到 例子: mysql> select * from information_schema.en ...