This is supposed to find a+B where A and B is the polynomials.
Input Specification:
Each input file contains the one test case. Each case occupies 2 lines, and all line contains the information of a polynomial:
KN?1??A?N?1????N?2??A?N?2???? ...N?K??a? N? K?? ??
whereK is the number of nonzero terms in the polynomial,N?I?? anda< Span class= "Vlist" >? n? i?? ?? (1,0.
Output Specification:
For each test case you should output The sum of A and B in one line, with the same format as T He input. Notice that there must is NO extra space at the end of each line. Accurate to 1 decimal place.
Sample Input:
2 1 2.4 0 3.22 2 1.5 1 0.5
Sample Output:
3 2 1.5 1 2.9 0 3.2
分析:
开一个1001的数组,直接用下标代替指数,存好两行数后相加,
输出数组内非零数即可
1#include <stdio.h>2 #defineN 10013 4 intMain () {5 floatv1[n]={0},v2[n]={0},res[n]={0};6 intX,n;7scanf"%d",&n);8 for(intI=0; i<n;++i) {9scanf"%d",&x);Tenscanf"%f", v1+x); One } Ascanf"%d",&n); - for(intI=0; i<n;++i) { -scanf"%d",&x); thescanf"%f", v2+x); - } - intCnt=0; - for(intI=0; i<n;++i) { +res[i]=v1[i]+V2[i]; - if(res[i]!=0) +cnt++; A } atprintf"%d", CNT); - for(intI=n;i>0; i--) - { - if(res[i-1]!=0) -printf"%d%.1f", I-1, res[i-1]); - } in return 0; -}
pat-Grade -1001-a+b for polynomials