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. LeetCode 107. Binary Tree Level Order Traversal II (二叉树阶层顺序遍历之二)

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  2. 阿里巴巴Java开发手册思维导图

    趁着有时间把阿里巴巴Java开发手册又看了一遍了,很多时候觉得看完之后,发现自己好像一点都不记得了里面的内容了.只能把大概内容画一遍在脑子里形成一张图方便记忆,这样就更能够记得自己的看完的内容了.其中 ...

  3. 微信小程序左滑删除功能

    效果图如下: wxml代码: <view class="container"> <view class="touch-item {{item.isTou ...

  4. java语言将任意一个十进制数数字转换为二进制形式,并输出转换后的结果

    package com.llh.demo; import java.util.Scanner; /** * * @author llh * */ public class Test { /* * 将任 ...

  5. poj2689Prime Distance(大区间筛素数)

    Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19635   Accepted: 5273 D ...

  6. 你不知的DOM编程

    前言:随着vue,react, angular的流行,可能现在我们不必经常的操作DOM,三大框架在副交互的操作中发挥着极大地优势.因为我们知道用脚本对DOM的操作非常昂贵,本文主要探讨常规的DOM操作 ...

  7. hbase的HQuorumPeer和QuorumPeerMain

    hbase是列式数据库,既可以单机也可以以集群的方式搭建,以集群的方式搭建一般建立在hdfs之上. 分布式的hbase如何启动? 首先启动hadoop,然后就来问题了:zookeeper和hbase的 ...

  8. 逆向课程第二讲,寻找main入口点

    逆向课程第二讲,寻找main入口点 一丶识别各个程序的入口点 入门知识,识别各个应用程序的入口点 (举例识别VC 编译器生成,以及VS编译生成的Debug版本以及Release版本) 1.识别VC6. ...

  9. PgSql on Docker with HaProxy 反向代理

    Run PgSql on Docker as Remote Db docker run -d -it \ --name pgdb \ -p 5432:5432 \ -e POSTGRES_USER=p ...

  10. 【吐槽】关于256个 class可以覆盖一个id的问题

    还是说今天下午面试的事情,被面试官问了 40多分钟的问题,我觉得丫 一定是从哪个网站down了几份面试题,自个儿整合了一下,然后挨个问,刚开始感觉哟,不错哦,面试官懂的蛮多的. 然后问到某个问题之后, ...