`
249326109
  • 浏览: 53716 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

1002. A+B for Polynomials (25)

 
阅读更多

链接:http://pat.zju.edu.cn/contests/pat-a-practise/1002

 

题意:多项式相加并且格式化输出。

 

分析:指数范围不大,可以简单用数组实现,数组的索引对应指数,内容对应系数。

 

 

#include<stdio.h>

double result[1005];

int main() {
	int k;
	scanf("%d", &k);
	int exp;
	double coe;
	while (k--) {
		scanf("%d%lf", &exp, &coe);
		result[exp] += coe;
	}
	scanf("%d", &k);
	while (k--) {
		scanf("%d%lf", &exp, &coe);
		result[exp] += coe;
	}

	int i;
	int count = 0;
	for (i = 0; i < 1005; i++) {
		if (result[i])
			count++;
	}

	printf("%d", count);
	for (i = 1005; i >= 0; i--) {
		if (result[i]) {
			printf(" %d %.1lf", i, result[i]);
		}
	}
	printf("\n");

	return 0;
}

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics