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. Chromebook 阿里云ECS 配置 jupyter Notebook

    前言 新购入一台Chromebook Pixel ,为方便机器学习编程,用学生版的阿里云ECS搭建了jupyter Notebook 为减少下次踩坑,参考链接记录如下: 参考链接 阿里云使用笔记(一) ...

  2. Android解析WindowManagerService(一)WMS的诞生

    前言 此前我用多篇文章介绍了WindowManager,这个系列我们来介绍WindowManager的管理者WMS,首先我们先来学习WMS是如何产生的.本文源码基于Android 8.0,与Andro ...

  3. map() Filter() lambda函数说明

    map()函数接收两个参数,一个是函数,一个是序列,map将传入的函数依次作用到序列的每个元素,并把结果作为新的list返回 #通过map()函数将list中的数字转换为字符 map(str,rang ...

  4. python错误和异常(1)

    1  SyntaxError: Python解释器语法错误,是唯一不是在运行时发生的异常. 2 检测和处理异常 try语句有两种主要形式:try-except 和 try-finally. 只能二选一 ...

  5. Python学习---Django路由系统【all】

    Django URL (路由系统) Django URL (路由系统): URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及要为该URL模式调用的视图函数之间的映 ...

  6. Python 处理脚本的命令行参数(二):使用click

    安装click pip install click 使用步骤 使用@click.command() 装饰一个函数,使之成为命令行接口 使用@click.option() 等装饰函数,为其添加命令行选项 ...

  7. charles license key

    Download: http://www.charlesproxy.com/ (Official Web-site) Registered name: anthony ortolani License ...

  8. Vue-Router基础使用

    作为Vue生态系统里面的一大成员,Vue-Router主要负责vue中的页面路由及其传值问题. 1.基本使用–添加路由 基本使用主要包括四个部分,页面引入.配置路由数组.实例化路由.把实例化的路由加入 ...

  9. css3-鼠标经过产品列表 图片放大 显示文字 (兼容IE9以上 不含IE9)

    <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8" /> <title&g ...

  10. Java对文件的读取方式以及它们的优缺点

    Java常用的对文件的读取方式基本包括: BufferedReader -> readLine(): 按行读取文件,直到读取内容==null FileInputStream -> read ...