当前位置:网站首页>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;
}
边栏推荐
- Wireshark网络抓包
- Bi skills - permission axis
- 请教一下 flinksql中 除了数据统计结果是状态被保存 数据本身也是状态吗
- How test engineers "attack the city" (Part 2)
- 模板_判断素数_开方 / 六素数法
- 物联网应用技术的就业前景和现状
- IBM WebSphere MQ retrieving messages
- Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
- Shell programming core technology "I"
- Oracle with as ora-00903: invalid table name multi report error
猜你喜欢

与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用

Nebula Importer 数据导入实践

物联网应用技术的就业前景和现状

“只跑一趟”,小区装维任务主动推荐探索

神经网络物联网应用技术就业前景【欢迎补充】

Oracle with as ORA-00903: invalid table name 多表报错

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

Opencv functions and methods related to binary threshold processing are summarized for comparison and use

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

每日一题(2022-07-02)——最低加油次数
随机推荐
YOLOv5s-ShuffleNetV2
26. Delete the duplicate item C solution in the ordered array
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
Using SSH
Have you guys ever used CDC direct Mysql to Clickhouse
C#实现定义一套中间SQL可以跨库执行的SQL语句(案例详解)
BI技巧丨权限轴
Send and receive IBM WebSphere MQ messages
SSL证书续费相关问题详解
国元期货是正规平台吗?在国元期货开户安全吗?
Shell programming core technology "three"
千万不要只学 Oracle、MySQL!
The kth largest element in the array
Lex and yacc based lexical analyzer + parser
Leetcode fizzbuzz C # answer
IBM WebSphere MQ retrieving messages
Oracle with as ORA-00903: invalid table name 多表报错
A method of using tree LSTM reinforcement learning for connection sequence selection
【uniapp】uniapp开发app在线预览pdf文件
php伪原创api对接方法