Daming A + B

 

Problem Description

In other words, after a long month, Xiao Ming has grown up a lot, so he changed a name called “Daming”. He was no longer the “Xiao Ming” who could only add up to 100. Now he could even add positive decimals of any length. Now, given two positive decimals A and B, your task is to calculate the value of A+B on behalf of Daming.

Input

This problem contains multiple sets of test data, please proceed to the end of the file. Each set of test data contains two positive decimals A and B of up to 400 in A row.

Output

Please print the value of A+B in one line, please print the simplest form. Please see detailed requirements

Sample Input

1.1 2.9

1.1111111111 2.3444323343

1, 1.1

Sample Output

4

3.4555434454

2.1

The question to describe

sum

Answer:

Store the integer part and the decimal part in an array and sum them separately.

Program code:

#include<stdio.h>
#include<string.h>
int Max(int a,int b);
int main(a)
{
	char str1[410],str2[410];
	int max1[410],min1[410],max2[410],min2[410];
	int i,l1,l2,p,q,m,n;
	
	while(scanf("%s%s",str1,str2)! =EOF) {memset(max1,0.sizeof(max1));
		memset(max2,0.sizeof(max2));
		memset(min1,0.sizeof(min1));
		memset(min2,0.sizeof(min2));
		l1=strlen(str1);
		l2=strlen(str2);
		p=0;
		q=0;
		for(i=0; str1[i]! ='\ 0'; i++) {if(str1[i]=='. ')
				break;
			else
				p++;
		}
		for(i=0; i<p; i++) max1[i]=str1[p- 1-i]-'0';
		for(i=0; i<l1- 1-p; i++) min1[i]=str1[p+1+i]-'0';
		for(i=0; str2[i]! ='\ 0'; i++) {if(str2[i]=='. ')
				break;
			else
				q++;
		}
		for(i=0; i<q; i++) max2[i]=str2[q- 1-i]-'0';
		for(i=0; i<l2- 1-q; i++) min2[i]=str2[q+1+i]-'0';
		m=Max((l1-p- 1),(l2-q- 1));
		for(i=m- 1; i>0; i--) { min1[i]+=min2[i];if(min1[i]>9)
			{
				min1[i]%=10;
				min1[i- 1] + +; } } min1[0]+=min2[0];
		if(min1[0] >9)
		{
			min1[0] % =10;
			max1[0] + +; } n=Max(p,q);
	
		for(i=0; i<n; i++) { max1[i]+=max2[i];if(max1[i]>9)
			{
				max1[i]%=10;
				max1[i+1] + +; }}if(max1[n]>0)
			for(i=n; i>=0; i--)printf("%d",max1[i]);
		else
			for(i=n- 1; i>=0; i--)printf("%d",max1[i]);
		while(1)
		{
			if(min1[m- 1] = =0)
				m--;
			else
				break;
		}
		if(m>0)
			printf(".");
		for(i=0; i<m; i++)printf("%d",min1[i]);
		printf("\n");
	}
	return 0;
}

int Max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
Copy the code