This time,you are supposed to find A+B where A+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 nonezero 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 asthe 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



题目大意:多项式合并同类项,按输入格式输出最后多项式的项数、各项的指数和系数。

分析:构造一个整型数组存放多项式的系数,输入时将相同指数的系数累加,如果累加之前数组存放的值为0,那么多项式的项数加1;如果累加之后等于0,那么多项式的项数减一。注意:多项式的指数都是整数,不要瞎想了~

#include <iostream>
using namespace std; double s[1005]={0};
int main() {
int k,n,time=2,count=0;
double ak;
while(time--){
scanf("%d",&k);
while(k--){
scanf(" %d %lf",&n,&ak);
if(s[n]==0)count++;
s[n]+=ak;
if(s[n]==0)count--;
}
}
printf("%d",count);
for(int i=1005;i>=0;i--){
if(s[i]!=0){
printf(" %d %.1lf",i,s[i]);
}
}
printf("\n");
return 0;
}

1002. A+B for Polynomials(25)—PAT 甲级的更多相关文章

  1. PAT甲级 1002 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 甲级1002 A+B for Polynomials (25)

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  3. PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...

  4. PAT 1002. A+B for Polynomials (25) 简单模拟

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  5. 【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 polynom ...

  6. PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  7. 1002 A+B for Polynomials (25)(25 point(s))

    problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...

  8. 【PAT甲级】1002 A+B for Polynomials (25 分)

    题意:给出两个多项式,计算两个多项式的和,并以指数从大到小输出多项式的指数个数,指数和系数. AAAAAccepted code: #include<bits/stdc++.h> usin ...

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

    题目描述: This time, you are supposed to find A+B where A and B are two polynomials. Input Each input fi ...

  10. PAT 1002. A+B for Polynomials (25)

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

随机推荐

  1. HTML 5 教程

    HTML5 是下一代的 HTML.有必要再过一遍.看下要点. 具体看  http://www.w3school.com.cn/html5/index.asp    教程 和  HTML5 标签参考手册 ...

  2. Bootstrap 在线引用

    Bootstrap 3.3.0 js 文件 <script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.j ...

  3. IntelliJ Idea编译报错:javacTask: 源发行版 1.8 需要目标发行版 1.8

    解决办法: 1.Project Settings-Modules,选择项目,选择language level 8 2.选中项目,右击选择Maven-->Reimport, 再次编译. 3.Fil ...

  4. 用jsp实现网站登录界面的制作,并连接数据库

    课堂测试 任务需求: 撰写一篇博客 需要网站系统开发需要掌握的技术: 本次课堂测试的源程序代码: 运行结果截图: 说明课堂测试未按时完成的原因. 列出你对这门课的希望和自己的目标,并具体列出你计划每周 ...

  5. .net core系列之《新一代的配置系统Configuration在支持多数据源,热更新,层级化方面代码快速实践》

    在我们之前.Net Framework的项目中,配置文件是WebConfig或AppcConfig文件,而当我们想要添加我们自定义的节点时,还需要在这个文件中的section中定义我们自定义的节点,这 ...

  6. CentOS随笔 - 3.CentOS7安装Oracle 11g xe

    前言 转帖请注明出处: http://www.cnblogs.com/Troy-Lv5/ 由于手上很多项目都是采用Oracle在进行开发, 所以安装Oracle成为必然. 当然有朋友会想为什么不安装1 ...

  7. 进程&多道技术

    进程 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的其他所有内容都 ...

  8. August 02nd 2017 Week 31st Wednesday

    Love means never having to say you are sorry. 爱就是永远不必说对不起. If there is ture love, you will never do ...

  9. php & laravel 相关收集

    http://www.oschina.net/news/49207/best-php-debugging-tools 调试相关工具 https://github.com/barryvdh/larave ...

  10. Oracle的四种连接方式【转载】

    我们以Oracle自带的表来做例子 主要两张表:dept.emp 一个是部门,一个是员工表结构如下: emp name null? Type Empno not null number(4) enam ...