当前位置:网站首页>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;
}
边栏推荐
- Educational Codeforces Round 22 E. Army Creation
- 一文掌握数仓中auto analyze的使用
- There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
- @transactional滥用导致数据源连接池耗尽问题
- 牛客小白月赛7 I 新建 Microsoft Office Word 文档
- The kth largest element in the array
- 2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
- 求2的n次方
- 用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
- Shell programming core technology "I"
猜你喜欢

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

Lm10 cosine wave homeopathic grid strategy

Online sql to excel (xls/xlsx) tool

Several methods of online database migration

There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks

FPGA timing constraint sharing 01_ Brief description of the four steps

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

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology

Bi skills - permission axis
随机推荐
Double colon function operator and namespace explanation
Have you guys ever used CDC direct Mysql to Clickhouse
Shell programming core technology "four"
HDU 6440 2018中国大学生程序设计网络选拔赛
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
生成XML元素
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
BCG 使用之CBCGPProgressDlg进度条使用
Some thoughts on whether the judgment point is located in the contour
QT realizes interface sliding switching effect
有关架构设计的个人思考(本文后续不断修改更新)
Hough Transform 霍夫变换原理
“只跑一趟”,小区装维任务主动推荐探索
PolyFit软件介绍
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
Stream流
The 300th weekly match of leetcode (20220703)
1672. Total assets of the richest customers
线上数据库迁移的几种方法
Generate XML elements