1002 A+B for Polynomials (25)(25 分)

This time, you are supposed to find A+B where A and B are two polynomials.

Input

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 ... NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, ..., K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10,0 <= NK < ... < N2 < N1 <=1000.

Output

For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

Sample Input

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output

3 2 1.5 1 2.9 0 3.2

思考

这里胡凡书上写的不全面,代码修正如下。

AC代码

#include <stdio.h>
#define max_n 1111
double p[max_n] = {};//这样也可以置初值为0
int main() {
int k, n, count = 0;
double a;
scanf("%d", &k);
count +=k;
for(int i = 0; i < k; i++) {
scanf("%d %lf", &n, &a);
p[n] += a;
}
scanf("%d", &k);
count +=k;
for(int i = 0; i < k; i++) {
scanf("%d %lf", &n, &a);
if(p[n]!=0) count--;//出现重合项-1
p[n] += a;
if(p[n]==0) count--;//出现重合项且一正一负抵消为0,再-1
}
// for(int i = 0; i < max_n; i++) {
// if(p[i] != 0) {
// count++;
// }//这样计数非零项是保险的
// }
printf("%d", count);
for(int i = max_n - 1; i >= 0; i--) {
if(p[i] != 0) printf(" %d %.1f", i, p[i]);
}
return 0;
}

A1002 A+B for Polynomials (25)(25 分)的更多相关文章

  1. PAT 甲级 1002 A+B for Polynomials (25 分)

    1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polyno ...

  2. 1009 Product of Polynomials (25 分)

    1009 Product of Polynomials (25 分) This time, you are supposed to find A×B where A and B are two pol ...

  3. pat 1002 A+B for Polynomials (25 分)

    1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polyno ...

  4. 怎么设置BarTender中二维码大小为25*25

    有小伙伴近期问了小编一个问题,说客户需要25*25大小的QR Code二维码,用BarTender怎么做出来?想要指定条形码的大小,还得BarTender符号与版本选项来帮忙.本文小编就来给大家详细讲 ...

  5. JAVA题目:正整数n若是其平方数的尾部,则称n为同构数 如:5*5=25, 25*25=625 问: 求1~99中的所有同构数

    1 /*题目:正整数n若是其平方数的尾部,则称n为同构数 2 如:5*5=25, 25*25=625 3 问: 求1~99中的所有同构数 4 */ 5 //分析:将1-99分为1-9和10-99,用取 ...

  6. 1002 A+B for Polynomials (25 分)

    This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each ...

  7. PAT A1009 Product of Polynomials (25 分)——浮点,结构体数组

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  8. PAT A1002 A+B for Polynomials(25)

    AC代码 转载自https://www.cnblogs.com/zjutJY/p/9413766.html #include <stdio.h> #include<string.h& ...

  9. 1002. A+B for Polynomials(25)—PAT 甲级

    This time,you are supposed to find A+B where A+B are two polynomials. Input Each input file contains ...

随机推荐

  1. PHP面试题及答案(五)

    1. 禁用COOKIE 后 SEESION 还能用吗? 答案: 不能. 2. 抓取远程图片到本地,你会用什么函数? 答案: fsockopen(). 3.求两个日期的差数,例如2007-2-5 ~ 2 ...

  2. VMware 虚拟机安装及部署

    Linux系统安装及网络配置 这篇文章介绍关于Linux系统的安装以及网络配置,关于虚拟机配置中网络的几个模式区别进行详细讲解.学习Linux对于后端开发人员来说是很有必要的,结合实际开发,Linux ...

  3. Google,真的要离我们而去吗?

    Google,真的要离我们而去吗? 好怀念,真正要解决问题,还得搜google!

  4. blog 题解目录

    洛谷: 1.P2430 严酷的训练 2.CF784E Twisted Circuit 3.P1886 滑动窗口 4.P1090 合并果子 5.P1119 灾后重建 6.P1690 贪婪的Copy 7. ...

  5. leetcode85 Maximal Rectangle

    思路: 分别按行拆分后将这一行之前的每列叠加起来,然后使用leetcode84https://www.cnblogs.com/wangyiming/p/9620942.html的思路计算. 实现: # ...

  6. html5标签的兼容性处理

    HTML5的语义化标签以及属性 1.可以让开发者非常方便地实现清晰的web页面布局,加上CSS3的效果渲染,快速建立丰富灵活的web页面显得非常简单 2.使用他们能让代码语义化更直观,而且更方便SEO ...

  7. Counting blessings can actually increase happiness and health by reminding us of the good things in life.

    Counting blessings can actually increase happiness and health by reminding us of the good things in ...

  8. LeetCode(605,581,566)

    LeetCode(605,581,566) 摘要:605盲改通过:581开始思路错误,后利用IDE修改(多重循环跳出方法):566用C语言时需要动态内存分配,并且入口参数未能完全理解,转用C++. 6 ...

  9. Android学习笔记1——Android开发环境配置

    一.JDK配置 Android是基于Java进行开发的,首先需要在电脑上配置JDK(Java Development Kit).在http://www.androiddevtools.cn/下载对应系 ...

  10. MySQL-5.6.30 (OpenLogic CentOS7.2)

    平台: CentOS 类型: 虚拟机镜像 软件包: centos7.2 mysql5.6.30 basic software database linux open source 服务优惠价: 按服务 ...