PAT (Advanced Level) Practice 1002 A+B for Polynomials

#include<stdio.h>

int main(){
	
	char ch;
	int count=1;
	double n1[1001]={0.0};
	double n2[1001]={0.0};
	double answer[1001]={0.0};
	int num;
	int a=0;
	double b=0.0;
	int max=0;
	int i;

	scanf("%d",&num);
	while(count<3){
		scanf("%d %lf",&a,&b);
		if(a>max){
			max=a;
		}
		if(count==1){
			n1[a]=b;
		}else if(count==2){
			n2[a]=b;
		}
		if((ch=getchar())=='\n'){
			count++;
			if(count==2){
				scanf("%d",&num);
			}
		}
	}
	count=0;
	for(i=max; i>=0; i--){
		answer[i]=(n1[i]+n2[i]);
		if(answer[i]!=0){
			count++;
		}
	}
	
	printf("%d",count);
	for(i=max; i>=0; i--){
		if(answer[i]!=0){
			printf(" %d %.1lf",i,answer[i]);
		}
	}
	
	return 0;
}

记录分享 love&share

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值