A1009 Product of Polynomials (25分)

1009 Product of Polynomials (25分)

Title address
Here Insert Picture Description
the Sample the Input:
2. 1 0 2.4 3.2
2 2 0.5 for 1.5. 1

Sample Output:
3 3 3.6 2 6.0 1 1.6

Subject to the effect

Multi-factor multiplication

  • It can be constructed, two arrays, or using an array and then ,,, struct
#include <stdio.h>
int main(){
	int n,m;
	double array[1010]={0},array2[1010]={0},array3[2020]={0};
	scanf("%d",&n);
	while(n--!=0){
		int x;double y;
		scanf("%d %lf",&x,&y); 
		array[x]=y;
		
	}
	scanf("%d",&m); 
	while(m--!=0){
		int x;double y;
		scanf("%d %lf",&x,&y); 
		array2[x]=y;
	}
	int count=0;
	for(int i=0;i<1010;i++){
		if(array[i]!=0){
			for(int j=0;j<1010;j++){
				if(array2[j]!=0){
					array3[i+j]+=array[i]*array2[j];
				}		
			}
		}
	} 	
	for (int i=0;i<2020;i++){
		if(array3[i]!=0){
			count++;
		}
	}
	printf("%d",count);
	for(int i=2020-1;i>=0;i--){
		if(array3[i]!=0){
			printf(" %d %0.1lf",i,array3[i]);
		} 
		
	}
} 
Published 91 original articles · won praise 9 · views 10000 +

Guess you like

Origin blog.csdn.net/WeDon_t/article/details/105252222