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
 #include<cstdio>
#include<iostream>
using namespace std;
int main(){
int K, n, count = ;
double poly1[] = {}, poly2[] = {}, a;
scanf("%d", &K);
for(int i = ; i < K; i++){
scanf("%d%lf", &n, &a);
poly1[n] = a;
}
scanf("%d", &K);
for(int i = ; i < K; i++){
scanf("%d%lf", &n, &a);
poly2[n] = a;
}
for(int i = ; i >= ; i--){
poly1[i] = poly1[i] + poly2[i];
if(poly1[i] != )
count++;
}
printf("%d", count);
for(int i = ; i >= ; i--){
if(poly1[i] != )
printf(" %d %.1lf", i, poly1[i]);
}
cin >> K;
return ; }

总结:

1、多项式加法,在项数不多的情况下直接开数组。

2、注意不用输出系数为0的项

A1002. A+B for Polynomials的更多相关文章

  1. A1002 A+B for Polynomials (25)(25 分)

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

  2. PAT甲级——A1002 A+B for Polynomials

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

  3. 【PAT】A1002 A+B for Polynomials

    仅有两个要注意的点: 如果系数为0,则不输出,所以输入结束以后要先遍历确定系数不为零的项的个数 题目最后一句,精确到小数点后一位,如果这里忽略了,会导致样例1,3,4,5都不能通过

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

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

  5. PAT/简单模拟习题集(二)

    B1018. 锤子剪刀布 (20) Discription: 大家应该都会玩"锤子剪刀布"的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负 ...

  6. PAT题目AC汇总(待补全)

    题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...

  7. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

  8. 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 ...

  9. 1002. A+B for Polynomials (25)

    题目链接:https://www.patest.cn/contests/pat-a-practise/1002 原题如下: This time, you are supposed to find A+ ...

随机推荐

  1. vue前端框架面试问题汇总

    1.active-class是哪个组件的属性?嵌套路由怎么定义?答:vue-router模块的router-link组件. 2.怎么定义vue-router的动态路由?怎么获取传过来的动态参数? 答: ...

  2. 部署ingress及使用

    一.下载yaml文件 wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.y ...

  3. mysql数据库的备份和还原的总结

    mysql数据库的备份和还原的总结 (来自一运维同事的总结) 1. 备份方式: 热备:数据库在线进行备份,不影响读和写的在线备份方式! 温备:数据库在线进行备份,对表备份时先锁定写操作,仅可以执行读操 ...

  4. Yii2后台管理系统常规单据模块最佳实践

    后台管理系统的常规单据通常包括数据,页面,功能:其中数据,页面,功能又可以细分如下: 分类  二级分类  主要内容  注意事项  例如 数据 数据库迁移脚本  用于数据表生成及转态回滚 1.是否需要增 ...

  5. 1064 - You have an error in your SQL syntax;

    mysql 1064 错误: SQL语法错误,check the manual that corresponds to your MySQL server version for the right ...

  6. How to SHA1 on macOS

    openssl sha1 /volumes/test/install/osx-test.dmg

  7. 学习 Spring (十七) Spring 对 AspectJ 的支持 (完结)

    Spring入门篇 学习笔记 @AspectJ 的风格类似纯 java 注解的普通 java 类 Spring 可以使用 AspectJ 来做切入点解析 AOP 的运行时仍旧是纯的 Spring AO ...

  8. 灰度图Matlab

    [转载]matlab中pcolor绘图“少画一行”的问题 本文是关于matlab pcolor函数(slice,surf函数的情况与这个类似)绘图的问题的一些解决方案,在此记录备用 经 常处理三维(或 ...

  9. Nginx upstream变量

    log_format varups '$upstream_addr $upstream_connect_time $upstream_header_time $upstream_response_ti ...

  10. EUV光刻!宇宙最强DDR4内存造出

    三星电子宣布开发出业内首款基于第三代10nm级工艺的DRAM内存芯片,将服务于高端应用场景,这距离三星量产1y nm 8Gb DDR4内存芯片仅过去16个月. 第三代10nm级工艺即1z nm(在内存 ...