题目描述:

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  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=, , ..., K) are the exponents and coefficients, respectively.
It is given that <= K <= , <= NK < ... < N2 < N1 <=. 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 decimal place. Sample Input
2.4 3.2
1.5 0.5 Sample Output
1.5 2.9 3.2 @:
polynomial 多项式
exponents 指数
coefficients 系数

题目要求:

给出俩个多项式的指数和系数,没有给出基数,只要将指数相同的多项式进行系数相加即可。输出时按照指数从高到低的顺序输出。

注意题意,一开始没有看题意直接看的实例,忽略了负数情况相加之后系数可能为零从而不写,所以常用的单词还是得认得。。。

 

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <math.h> using namespace std; int main()
{
int i,j,a,n;
int con=;
double s[],b;
int vis[];
memset(s,,sizeof(s));
memset(vis,,sizeof(vis)); for(i=;i<;i++)
{
scanf("%d", &n);
for(j=;j<n;j++)
{
scanf("%d %lf",&a,&b);
s[a]+=b;
}
} for(i=;i<=;i++)
if(s[i]!=)
con++; printf("%d", con); for(i=;i>=;i--)
if(s[i]!=)
printf(" %d %.1f",i,s[i]); printf("\n"); return ;
}

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

  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 1002. A+B for Polynomials (25) 简单模拟

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

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

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

  6. 【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 ...

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

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

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

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

随机推荐

  1. PL/SQL 条件控制语句

    1.if-then 语句 语法: IF 条件 THEN 语句序列; END IF; 实例: DECLARE i ) :; BEGIN THEN dbms_output.put_line('True') ...

  2. 浅谈Quartz(SimpleTrigger&CronTrigger)

    private void quartzOrderReturn(List<String> returnIds) { try { Scheduler scheduler = StdSchedu ...

  3. 搭建一个java开发环境的步骤

    首先思考java开发环境需要些什么? 1.适用于我们开发环境的jdk 2.对应开发环境的IDE 3.如果是web应用,还需要web服务器,常用的有Tomcat 1) 下载对应组件 2) 安装 jdk安 ...

  4. Sass 基础(三)

    扩展/继承 继承对于了解css 的同学来说一点都不陌生,先来看一张图 在Sass 中也具有继承一说,也就是继承类中的样式代码块,在Sass中时通过关键词“@extend”来 继承已经存在的类样式块,从 ...

  5. substr在oracle和mysql中的应用和区别

    Oracle: 书写格式: (1)Select  substr(字段名(string) , 起始位置(int) , 截取长度(int)) 示例: selectsubstr('123456',0,3)a ...

  6. dom4j解析器sax解析xml文件

    1.使用dom4j解析器解析xml ***解析器dom4j是由dom4j组织提供的,针对xml进行解析.dom4j不是Javase的一部分,使用时需要导入dom4j的jar包(官网下载) 在eclip ...

  7. web3.js_1.x.x--API(一)event/Constant/deploy/options

    /* 事件是使用EVM日志内置功能的方便工具,在DAPP的接口中,它可以反过来调用Javascript的监听事件的回调. 事件在合约中可被继承.当被调用时,会触发参数存储到交易的日志中(一种区块链上的 ...

  8. 微信小程序使用相机

    <view class="page-body"> <view class="page-body-wrapper"> <camera ...

  9. JavaScript 转载

    JavaScript概述 ECMAScript和JavaScript的关系 1996年11月,JavaScript的创造者--Netscape公司,决定将JavaScript提交给国际标准化组织ECM ...

  10. pycharm中每次创建py文件时就自动生成代码头,以及出现SyntaxError:Non-ASCII 。。。问题

    我们在pycharm中执行py文件的时候,可能会出现以下错误 这是因为你没有制定编码格式,这时候你需要在文件最开始制定编码格式,代码如下 #!/user/bin/env python #-*- cod ...