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. .NET AOP微型框架发布 --CleanAOP

    CleanAOP--简介 作者:立地(欧文) 邮箱:jarvin_g@126.com 导语: AOP为Aspect Oriented Programming的缩写. 意为:面向切面编程.将日志记录,性 ...

  2. mac下 IDEA 的pom下 出现 Cannot access in offline mode 问题

    在mac下 配置完maven后发现总是不能引入最新的jar包,google了好久总算找到解决办法: 默认带有work offline ,不清楚这个是干嘛用的.勾选掉 了就行了.

  3. oracle基础之游标的理解与使用

    关于游标,首先要知道游标的定义. 游标,是内存中的一款区域,用来存放select的结果集 游标用来处理从数据库中检索的多行记录(使用select语句).利用游标,程序可以逐个的处理和遍历一次索引返回的 ...

  4. spring boot(6)-JdbcTemplate访问数据库

     pom.xml 添加jdbc模块和mysql依赖 <dependency> <groupId>org.springframework.boot</groupId&g ...

  5. 提示"libc.so.6: version `GLIBC_2.14' not found"

    启动php 提示"libc.so.6: version `GLIBC_2.14' not found",原因可能是glibc版本太低,php使用了较高的glibc版本引起的 1,首 ...

  6. Django objects.all() ,objects.get() ,objects.filter()之间的区别

    ret=UserInfo.objects.all() all返回的是QuerySet对象,程序并没有真的在数据库中执行SQL语句查询数据,但支持迭代,使用for循环可以获取数据. ret=UserIn ...

  7. 《深入理解mybatis原理》 Mybatis数据源与连接池

    对于ORM框架而言,数据源的组织是一个非常重要的一部分,这直接影响到框架的性能问题.本文将通过对MyBatis框架的数据源结构进行详尽的分析,并且深入解析MyBatis的连接池. 本文首先会讲述MyB ...

  8. Python 爬虫练习项目——异步加载爬取

    项目代码 from bs4 import BeautifulSoup import requests url_prefix = 'https://knewone.com/discover?page=' ...

  9. 定义类、System.Object对象、构造函数与析构函数、抽象类与静态类

    一.类定义 class MyClass { //类成员 } 1.访问级别 默认访问级别为internal(内部类),也可以是public(公共类) internal(内部类):当前项目中的代码才能访问 ...

  10. js调用echarts getImage方法 将图表转换为img

    function chart(opt,id,chartName){//配置option的方法 var chartName = echarts.init(document.getElementById( ...