1002. A+B for Polynomials (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 2 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=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 as the 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,不输出。最后一种情况,没有存在项,输出"0\n"

源代码:

 #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int na,nb;
scanf("%d",&na);
int flag[]={};
double res[]={};
int index;double data;
for(int i=;i<na;++i) {
scanf("%d %lf",&index,&data);
flag[index]=;
res[index]+=data;
}
scanf("%d",&nb);
for(int i=;i<nb;++i) {
scanf("%d %lf",&index,&data);
flag[index]=;
res[index]+=data;
}
int cnt=;
for(int i=;i<=;++i) {
if(flag[i]&&fabs(res[i])>1e-)
cnt++;
}
if(cnt==) {
printf("");
} else {
printf("%d ",cnt);
}
for(int i=;i>=;--i) {
if(flag[i]&&fabs(res[i])>1e-) {
printf("%d %.1lf",i,res[i]);
cnt--;
if(cnt==) {
break;
} else {
printf(" ");
}
}
}
printf("\n");
return ;
}

PAT 1002. A+B for Polynomials (25) 简单模拟的更多相关文章

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

  2. PAT 1002 A+B for Polynomials (25分)

    题目 This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: E ...

  3. PAT 1002 A+B for Polynomials(map模拟)

    This time, you are supposed to find A+B where A and B are two polynomials(多项式). Input Each input fil ...

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

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

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

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

随机推荐

  1. 使用 Hadoop 进行语料处理(面试题)

    原创播客,如需转载请注明出处.原文地址:http://www.cnblogs.com/crawl/p/7751741.html ------------------------------------ ...

  2. js 两个日期比较相差多少天

    var day1 = new Date("2017-9-17"); var day2 = new Date("2017-10-18"); console.log ...

  3. js 获取多少天前

    getBeforeDate: function(day, str) { var now = new Date().getTime(); //获取毫秒数 var before = new Date(no ...

  4. Autofac学习之三种生命周期:InstancePerLifetimeScope、SingleInstance、InstancePerDependency

    InstancePerLifetimeScope:同一个Lifetime生成的对象是同一个实例 SingleInstance:单例模式,每次调用,都会使用同一个实例化的对象:每次都用同一个对象: In ...

  5. Android: Only the original thread that created a view hierarchy can touch its views 异常

    最近自己再写一个小项目练手,创建一个线程从网络获取数据然后显示在 recyclerView 上.写好后发现页面能够显示,但是有时候会把请求的数据显示过来,有时候不会.点开 android monito ...

  6. BZOJ-2463

    2463: [中山市选2009]谁能赢呢? Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2321  Solved: 1711[Submit][Sta ...

  7. 理解Java包

    本质上,包是一个唯一命名的类的集合,将类集合到包里面的主要原因,是为了当在应用程序中使用预先编写的类时避免与类自身可能引起的明明冲突.用于包中的类名不会妨碍另一个包或程序中的类名,因为此时,包中的类名 ...

  8. HTTP服务简介

    第1章 HTTP服务介绍 1.1 简述用户访网站流程 a 进行域名信息的DNS解析   dig +trace 获得www.oldboyedu.com  ip地址信息 b 进行与网站服务器建立连接,tc ...

  9. html网页中加载js脚本 下载下来是乱码(文件编码格式)

    问题描述: 在一个index.html网页中,引入了jquery脚本,但是却出现错误,提示$ is not defined <!DOCTYPE html> <html lang=&q ...

  10. svg snap 笔记

    路径中的字母,大写相对于左上角绝对定位,小写相对定位  M110,95,95,110M115,100,100,115   pattern 类似于图片拼贴,可以把指定位置的图案用来填充 var patt ...