1. 程式人生 > >杭電oj-1002

杭電oj-1002

Problem 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 <cstring>
 #include<algorithm> 
 using namespace std;
 int main ()
 {
 	int a;
 	cin>>a;
 	for(int b=0;b<a;b++)
 	{
 	char c [10000],d[10000],f[10000],maxArray[10000],g[10000],i[10000];
 	int c_long=0;
	int d_long=0; 
 
 	for(int e=0;e<10000;e++)
 	{
 		f[e]='0';
	 }
 	
 		cin>>c>>d;
 		for(int e=0;e<strlen(c);e++)
 		{
 			g[e]=c[e];
 			c_long++;
		 }
		 for(int e=0;e<strlen(d);e++)
		 {
		 	i[e]=d[e];
		 	d_long++;
		 	
		 } 
 		reverse(c,c+strlen(c));
 		reverse(d,d+strlen(d));
 		
 		int min_long, max_long;
 		if(strlen(c)>strlen(d))
 		{
 			min_long=strlen(d);
 			max_long=strlen(c);
 			for(int e=0;e<strlen(c);e++)
 			{
 				maxArray[e]=c[e];
			 }
		 }
		 else
		{
			min_long=strlen(c);
			max_long=strlen(d);
		
			for(int e=0;e<strlen(d);e++)
			{
				maxArray[e]=d[e];
			}
		}
 		for(int e=strlen(c);e<10000;e++)
 		{
 			c[e]='0';
		 }
		for(int e=strlen(d);e<10000;e++)
		{
			d[e]='0';
		}
 		
 		
 		int temp=0;
 		int num=0;
 		for(int e=0;e<10000;e++)
 		{
 			 temp = temp+(c[e]-'0')+(d[e]-'0');
 			f[e]=temp%10+'0';
 			temp=temp/10;
 			
 			if(e>=max_long)
 			{
 				num++;
			 }
 			if(e>=max_long-1&&temp==0)
 			{
 			
 				break;
			 }
 			
		 }	
		  cout<<"Case "<<b+1<<":"<<endl;
		  for(int e=0;e<c_long;e++)
		  {
		  	cout<<g[e];
		  }
		 cout<<" + ";
		 for(int e=0;e<d_long;e++)
		 {
		 	cout<<i[e];
		 }
		 cout<<" = ";
		 for(int e=max_long-1+num;e>=0;e--)
		 {
		 	cout<<f[e];
		 }
	
		 
		
		 
		 cout<<endl;
		 if(b!=a-1)
		 cout<<endl;

	 }
	 
	 
  }