pat-Grade -1001-a+b for polynomials

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.