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. WPF使用样式更新ArcGis InfoWindow外观代码

    <Style x:Key="mainInfoWindowStyleMF" TargetType="{x:Type esri:InfoWindow}"> ...

  2. c++开源日志log4cplus使用开发文档

    下载地址:http://files.cnblogs.com/files/lizhigang/LOG4CPLUS%E5%BC%80%E5%8F%91%E4%B8%8E%E4%BD%BF%E7%94%A8 ...

  3. ubuntu下面解压tar.gz包报错:tar命令报错: gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error

    原因: 压缩包文件不完整(损坏或者其他原因) 比如今天下载的tomcat8,使用ubuntu的命令下载的 curl -O http://apache.mirrors.ionfish.org/tomca ...

  4. Head First HTML和CSS(一)

    Web语言 HTML和CSS是我们用来创建网页的语言. Web服务器存储并提供由HTML和CSS创建的网页,浏览器获取页面,并根据HTML和CSS显示网页的内容 HTML是超文本标记语言(HyperT ...

  5. 查询SQL Version详细信息

    下面是一个查询SQL Server版本并给出升级建议的SQL代码,用来学习写SQL代码. ------------------------------------------------------- ...

  6. 让UpdatePanel支持文件上传(2):服务器端组件 .

    我们现在来关注服务器端的组件.目前的主要问题是,我们如何让页面(事实上是ScriptManager控件)认为它接收到的是一个异步的回送?ScriptManager控件会在HTTP请求的Header中查 ...

  7. php测试工具

    如果是测压力有apache的ab如果要看性能则有xdebug和xhprof.还有linux的strace命令来跟踪程序的执行时的系统调用

  8. php中的html元素

    我们先看下面的代码 form2.php <html> <head><title>greetins eartyling</title></head& ...

  9. [EffectiveC++]item24:若所有参数皆需类型转换,请为此采用non-member函数

    Declare non-member functions when type conversions should apply to all parameters. 104页 只有当参数被列于参数列( ...

  10. LINUX下OA搭建