当前位置:网站首页>1002. A+B for Polynomials (25)(PAT甲级)
1002. A+B for Polynomials (25)(PAT甲级)
2022-07-04 17:59:00 【相思明月楼】
Problem Description
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>
#include <cstdio>
using namespace std;
double ans[1005];
int main() {
int k1, k2, n;
double a;
scanf("%d", &k1);
for(int i = 0; i < k1; i++) {
scanf("%d %lf", &n, &a);
ans[n] += a;
}
scanf("%d", &k2);
for(int i = 0; i < k2; i++) {
scanf("%d %lf", &n, &a);
ans[n] += a;
}
int cnt = 0;
for(int i = 0; i <= 1000; i++) {
if(ans[i] != 0) {
cnt++;
}
}
printf("%d", cnt);
for(int i = 1001; i >= 0; i--) {
if(ans[i] != 0) {
printf(" %d %.1lf", i, ans[i]);
}
}
return 0;
}
边栏推荐
- 1672. 最富有客户的资产总量
- 2021 合肥市信息学竞赛小学组
- 更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
- 2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
- 自由小兵儿
- Pointnet/Pointnet++点云数据集处理并训练
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
- repeat_P1002 [NOIP2002 普及组] 过河卒_dp
- 国元期货是正规平台吗?在国元期货开户安全吗?
猜你喜欢
Summary and sorting of 8 pits of redis distributed lock

Lm10 cosine wave homeopathic grid strategy

Go microservice (II) - detailed introduction to protobuf

Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples

PolyFit软件介绍

千万不要只学 Oracle、MySQL!

Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?

在线文本行固定长度填充工具

DeFi生态NFT流动性挖矿系统开发搭建

To sort out messy header files, I use include what you use
随机推荐
Send and receive IBM WebSphere MQ messages
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
Unity editor extends C to traverse all pictures in folders and subdirectories
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
神经网络物联网平台搭建(物联网平台搭建实战教程)
更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
Bi skills - permission axis
How to use async Awati asynchronous task processing instead of backgroundworker?
Nebula importer data import practice
26. Delete the duplicate item C solution in the ordered array
Technology sharing | interface testing value and system
函数式接口
Shell 编程核心技术《三》
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
LeetCode第300场周赛(20220703)
In flinksql, in addition to data statistics, is the saved data itself a state
Shell 编程核心技术《二》
One question per day (2022-07-02) - Minimum refueling times