当前位置:网站首页>1002. A+b for Polynomials (25) (PAT class a)
1002. A+b for Polynomials (25) (PAT class a)
2022-07-04 19:36:00 【Acacia moon tower】
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
The addition of polynomials ,
#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;
}
边栏推荐
- 牛客小白月赛7 F题
- OpenCV的二值化处理函数threshold()详解
- How to use async Awati asynchronous task processing instead of backgroundworker?
- Use canal and rocketmq to listen to MySQL binlog logs
- HDU 1097 A hard puzzle
- 如何使用Async-Awati异步任务处理代替BackgroundWorker?
- HMM隐马尔可夫模型最详细讲解与代码实现
- 与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
- node_exporter部署
- Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
猜你喜欢

Detailed explanation of the binary processing function threshold() of opencv

SSRS筛选器的IN运算(即包含于)用法

如何使用Async-Awati异步任务处理代替BackgroundWorker?

Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?

LM10丨余弦波动顺势网格策略

The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize

【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案

mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总

MySQL数据库基本操作-DDL | 黑马程序员

OpenCV的二值化处理函数threshold()详解
随机推荐
1005 Spell It Right(20 分)(PAT甲级)
Qt实现界面滑动切换效果
Leetcode fizzbuzz C # answer
Summary and sorting of 8 pits of redis distributed lock
LeetCode第300场周赛(20220703)
Wechat reading notes of "work, consumerism and the new poor"
Oracle with as ORA-00903: invalid table name 多表报错
To sort out messy header files, I use include what you use
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
Pytest 可视化测试报告之 Allure
prometheus安装
Wireshark网络抓包
测试工程师如何“攻城”(下)
TCP两次挥手,你见过吗?那四次握手呢?
Socket programming demo II
Generate XML elements
1006 Sign In and Sign Out(25 分)(PAT甲级)
QT realizes interface sliding switching effect
1009 Product of Polynomials(25 分)(PAT甲级)
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting