当前位置:网站首页>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;
}
边栏推荐
- 如何使用Async-Awati异步任務處理代替BackgroundWorker?
- The 15th youth informatics competition in Shushan District in 2019
- Shell 編程核心技術《四》
- Go微服务(二)——Protobuf详细入门
- 如何使用Async-Awati异步任务处理代替BackgroundWorker?
- 用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
- 奥迪AUDI EDI INVOIC发票报文详解
- IBM WebSphere MQ retrieving messages
- Pytest 可视化测试报告之 Allure
- Cache é JSON uses JSON adapters
猜你喜欢
读写关闭的channel是啥后果?
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
奥迪AUDI EDI INVOIC发票报文详解
Pointnet/Pointnet++点云数据集处理并训练
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
Use canal and rocketmq to listen to MySQL binlog logs
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
神经网络物联网应用技术就业前景【欢迎补充】
升级智能开关,“零火版”、“单火”接线方式差异有多大?
性能优化之关键渲染路径
随机推荐
Have you guys ever used CDC direct Mysql to Clickhouse
Qt实现界面滑动切换效果
Bi skills - permission axis
To sort out messy header files, I use include what you use
A method of using tree LSTM reinforcement learning for connection sequence selection
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
Leetcode fizzbuzz C # answer
repeat_P1002 [NOIP2002 普及组] 过河卒_dp
Oracle with as ora-00903: invalid table name multi report error
自由小兵儿
LeetCode第300场周赛(20220703)
The kth largest element in the array
Build your own website (15)
Shell programming core technology II
How test engineers "attack the city" (Part I)
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
LeetCode FizzBuzz C#解答
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
FPGA时序约束分享01_四大步骤简述
26. 删除有序数组中的重复项 C#解答