当前位置:网站首页>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;
}
边栏推荐
- 线上数据库迁移的几种方法
- Explicit random number
- 1006 Sign In and Sign Out(25 分)(PAT甲级)
- An example of multi module collaboration based on NCF
- ftp、sftp文件传输
- The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
- Unity编辑器扩展C#遍历文件夹以及子目录下的所有图片
- Go microservice (II) - detailed introduction to protobuf
- 1672. Total assets of the richest customers
- 函数式接口
猜你喜欢

PolyFit软件介绍

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

在线文本行固定长度填充工具

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

Bi skills - permission axis

The 300th weekly match of leetcode (20220703)

LeetCode第300场周赛(20220703)

如何使用Async-Awati异步任務處理代替BackgroundWorker?

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行

92.(cesium篇)cesium楼栋分层
随机推荐
FPGA timing constraint sharing 01_ Brief description of the four steps
Shell 编程核心技术《四》
How to use async Awati asynchronous task processing instead of backgroundworker?
测试工程师如何“攻城”(下)
FTP, SFTP file transfer
Online text line fixed length fill tool
HDU 1097 A hard puzzle
LM10丨余弦波动顺势网格策略
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
HMM隐马尔可夫模型最详细讲解与代码实现
Specify the character set to output
Hough Transform 霍夫变换原理
How test engineers "attack the city" (Part 2)
C# 使用StopWatch测量程序运行时间
关于判断点是否位于轮廓内的一点思考
Wechat reading notes of "work, consumerism and the new poor"
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
如何使用Async-Awati异步任务处理代替BackgroundWorker?
The 300th weekly match of leetcode (20220703)
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用