当前位置:网站首页>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;
}
边栏推荐
- 自由小兵儿
- LM10丨余弦波动顺势网格策略
- Is Guoyuan futures a regular platform? Is it safe to open an account in Guoyuan futures?
- 2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
- 升级智能开关,“零火版”、“单火”接线方式差异有多大?
- sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
- In flinksql, in addition to data statistics, is the saved data itself a state
- 请教一下 flinksql中 除了数据统计结果是状态被保存 数据本身也是状态吗
- Summary and sorting of 8 pits of redis distributed lock
- How test engineers "attack the city" (Part 2)
猜你喜欢

One question per day (2022-07-02) - Minimum refueling times

FPGA时序约束分享01_四大步骤简述

英特尔集成光电研究最新进展推动共封装光学和光互连技术进步

To sort out messy header files, I use include what you use

千万不要只学 Oracle、MySQL!
![[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0](/img/4e/4154fec22035725d6c7aecd3371b05.jpg)
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0

Use canal and rocketmq to listen to MySQL binlog logs

正则替换【JS,正则表达式】

整理混乱的头文件,我用include what you use

Pointnet/Pointnet++点云数据集处理并训练
随机推荐
神经网络物联网应用技术学什么
自由小兵儿
Shell programming core technology "four"
问下各位大佬有用过cdc直接mysql to clickhouse的么
使用canal配合rocketmq监听mysql的binlog日志
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
Shell programming core technology "three"
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)
整理混乱的头文件,我用include what you use
IBM WebSphere MQ retrieving messages
从实时应用角度谈通信总线仲裁机制和网络流控
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
php伪原创api对接方法
每日一题(2022-07-02)——最低加油次数
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
[uniapp] uniapp development app online Preview PDF file
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
Download the first Tencent technology open day course essence!
876. Intermediate node of linked list