首页 > 试题广场 >

求两个多项式的和

[编程题]求两个多项式的和
  • 热度指数:5054 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
输入两个多项式,计算它们的和。 每个多项式有若干对整数表示,每组整数中,第一个整数表示系数(非0),第二个整数表示该项的次数。 如由3 3 5 -2 1 4 0表示3x^5 - 2 * x + 4其中第一个3表示该多项式由三个整数对表示。

输入描述:
输入为两行,分别表示两个多项式。表示每项的整数对按照次数大小降序给出。(次数绝对值小于1000,系数绝对值小于10000)


输出描述:
按照降次顺序输出表示和多项式的整数对(系数为0的整数对不用输出,整数对由空格分隔,最后一个整数对后不添加空格)
示例1

输入

3 3 5 -2 1 4 0
4 2 3 -1 2 1 1 3 0

输出

3 5 2 3 -1 2 -1 1 7 0
头像 牛客440904392号
发表于 2024-10-06 16:24:09
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] 展开全文
头像 L456
发表于 2024-03-22 16:28:40
#include <bits/stdc++.h> using namespace std; int main() { int na,nb; map<int,int> ma,mb; cin>>na; while(na--) { int x,y; 展开全文
头像 爱吃的懒羊羊离上岸不远了
发表于 2025-03-11 15:20:00
#include <iostream> #include <algorithm> #include <cmath> #include <cstring> #define maxn 2010 using namespace std; int a[maxn 展开全文
头像 marlin818
发表于 2024-03-17 16:50:52
#include <iostream> #include <map> using namespace std; map<int, int, greater<int>> mp; //次数, 系数 int main(){ int n, m; 展开全文
头像 Jonas_LEE
发表于 2025-03-11 19:54:27
利用归并排序思想,随后逆序输出 #define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <map> using namespace std; int main() { int n, m; map& 展开全文
头像 黄金回旋02
发表于 2025-03-18 15:10:30
#include <bits/stdc++.h> using namespace std; int main() { int num,xishu,cishu,max_ci=-1000,min_ci=1000; map<int,int>m; while 展开全文