当前位置:网站首页>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;
}
边栏推荐
- Shell programming core technology II
- 小发猫物联网平台搭建与应用模型
- The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
- LeetCode第300场周赛(20220703)
- Opencv functions and methods related to binary threshold processing are summarized for comparison and use
- repeat_P1002 [NOIP2002 普及组] 过河卒_dp
- php伪原创api对接方法
- Other InterSystems%net tools
- Leetcode ransom letter C # answer
- 长城证券开户安全吗 买股票怎么开户
猜你喜欢
[release] a tool for testing WebService and database connection - dbtest v1.0
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Nebula Importer 数据导入实践
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
自由小兵儿
从实时应用角度谈通信总线仲裁机制和网络流控
性能优化之关键渲染路径
Use canal and rocketmq to listen to MySQL binlog logs
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
随机推荐
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
神经网络物联网应用技术学什么
Shell programming core technology "I"
Shell 編程核心技術《四》
Go microservice (II) - detailed introduction to protobuf
建立自己的网站(15)
如何使用Async-Awati异步任務處理代替BackgroundWorker?
Process of manually encrypt the mass-producing firmware and programming ESP devices
Wireshark网络抓包
神经网络物联网是什么意思通俗的解释
MySQL数据库基本操作-DDL | 黑马程序员
YOLOv5s-ShuffleNetV2
Is Guoyuan futures a regular platform? Is it safe to open an account in Guoyuan futures?
The kth largest element in the array
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
Pytorch学习(四)
物联网应用技术的就业前景和现状
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
Shell 编程核心技术《三》
一文掌握数仓中auto analyze的使用