本文共 1857 字,大约阅读时间需要 6 分钟。
本来想在原来做的pta博客上再附上java实现的代码,发现这道题没写博客,那只好补发一波了,hhh
This time, you are supposed to find A+B where A and B are two polynomials.
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.
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.
2 1 2.4 0 3.22 2 1.5 1 0.5
3 2 1.5 1 2.9 0 3.2
多项式计算,给出两个多项式的项数,然后按照指数递减的顺序给出系数和指数。输出最后的项数和各个项的系数和指数。
其实就是类似于链表合并操作,坑点是注意系数为0不能出现在结果中。
#includeusing namespace std;const int maxn=1e3+5;int n,m;struct pol { int zhi; double xi;};vector ans;pol a[maxn],b[maxn];int numa=0,numb=0;int main(){ scanf("%d",&n); for (int i=0;i =numb)||(a[i].zhi>b[j].zhi)) { pol x; x.zhi=a[i].zhi; x.xi=a[i].xi; ans.push_back(x); i++; } else if((i>=numa)||(b[j].zhi>a[i].zhi)) { pol x; x.zhi=b[j].zhi; x.xi=b[j].xi; ans.push_back(x); j++; } else if(i
import java.util.ArrayList;import java.util.List;import java.util.Scanner;/** * @classname: Adv1002 * @description: TODO * Author : asus * Date : 2019/10/24 20:02 * Version: 1.0 **/public class Main { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int num1 = sc.nextInt(); Listlist1 = new ArrayList<>(); List list2 = new ArrayList<>(); List rs = new ArrayList<>(); int re0 = 0; for (int i=0;i
转载地址:http://hdaen.baihongyu.com/