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 polynomials.
Input Specification:
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 Specification:
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
#include<iostream>
using namespace std;
int main() {
double N[1001] = {0}, m;
int k, max = 0, tmp, count=0;
for (int i = 0; i < 2; i++) {
cin >> k;
for (int j = 0; j < k; j++) {
cin >> tmp >> m;
max = tmp > max ? tmp : max;
N[tmp] += m;
}
}
for (int i = 0; i <= max; i++) {
if (N[i] != 0)
count++;
}
cout << count;
if (count > 0) {
for (int i = max; i >=0; i--) {
if (N[i] != 0) {
cout << " " << i << " ";
printf("%0.1lf", N[i]);
}
}
}
return 0;
}
PAT 甲级 1002 A+B for Polynomials (25 分)的更多相关文章
- 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 ...
- PAT 甲级1002 A+B for Polynomials (25)
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT Advanced 1002 A+B for Polynomials (25 分)(隐藏条件,多项式的系数不能为0)
This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each ...
- 【PAT甲级】1009 Product of Polynomials (25 分)
题意: 给出两个多项式,计算两个多项式的积,并以指数从大到小输出多项式的指数个数,指数和系数. trick: 这道题数据未知,导致测试的时候发现不了问题所在. 用set统计非零项时,通过set.siz ...
- 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 ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT甲级:1089 Insert or Merge (25分)
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...
- 【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 ...
- PAT 甲级 1145 Hashing - Average Search Time (25 分)(读不懂题,也没听说过平方探测法解决哈希冲突。。。感觉题目也有点问题)
1145 Hashing - Average Search Time (25 分) The task of this problem is simple: insert a sequence of ...
随机推荐
- Linux umask命令详解
Linux umask命令 Linux umask命令指定在建立文件时预设的权限掩码.一般来说,umask命令是在/etc /profile文件中设置的 umask可用来设定[权限掩码].[权限掩码] ...
- BCC校验小知识
BCC校验其实是奇偶校验的一种,但也是经常使用并且效率较高的一种.所谓BCC校验法,就是在发送前和发送后分别把BCC以前包括ETX字符的所有字符按位异或后,按要求变换(增加或去除一个固定的值)后所得到 ...
- oData 排序字段生成
跟踪SQL 发现生成的SQL中所有的字段都进行了排序,查看OData原代码,发现如果实体有Key,就按照Key asc 加上指定字段进行排序 属性 EnsureStableOrdering可以控制是否 ...
- Class 泛型
Java Class 泛型的例子说明: http://blog.chinaunix.net/uid-1911213-id-3085866.html http://blog.163.com/sir_87 ...
- centos7.6+samba+设置可读可写不可删权限
samba原文 https://www.cnblogs.com/muscleape/p/6385583.html 设置可读可写不可删权限原文: https://blog.51cto.com/guanh ...
- leetcode14:最长公共字符串
编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow" ...
- python -反射hasattr、setattr、delattr
login.py #!/usr/bin/dev python# coding:utf-8 def index(): print u'欢迎访问xx网站首页' def login(): print u'登 ...
- ElasicSearch(2) Linux运行
1.org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearc ...
- 预浸料(Prepreg,PreimpregnatedMaterials)
预浸料(Prepreg,PreimpregnatedMaterials),是把基体(Matrix)浸渍在强化纤维(Reinforced Fiber)中制成的预浸片材产品,是复合材料的中间材料.
- nginx的一次工作记录
upstream fazhi_ui{ server ; } upstream fazhi_api{ server ; } server { listen ; server_name localhost ...