1009. Product of polynomials (25) -- Pat (Advanced Level) practise

Source: Internet
Author: User
Question information:
1009. Product of polynomials (25) Time Limit 400 MS
The memory limit is 32000 kb.
Code length limit: 16000 B
Criterion author Chen, Yue

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 N1N1 N2N2... NKNK, where k is the number of nonzero terms in the polynomial, Ni andNi (I = 1, 2 ,..., k) are the exponents and coefficients, respectively. it is given that 1 <= k <= 10, 0 <= NK <... <N1 <= 1000.

Output specification:

For each test case you shoshould output the product 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 up to 1 decimal place.

Sample Input
2 1 2.4 0 3.22 2 1.5 1 0.5
Sample output
3 3 3.6 2 6.0 1 1.6



The Code is as follows:

#include <iostream>#include <map>using namespace std;int main(){map<int, float> m1, m2, m3;int k, n;float a;cin >> k;for (int i = 0; i < k; i++){cin >> n >> a;m1[n] = a;}cin >> k;for (int i = 0; i < k; i++){cin >> n >> a;m2[n] = a;}for (map<int, float>::iterator it1 = m1.begin(); it1 != m1.end(); it1++){for (map<int, float>::iterator it2 = m2.begin(); it2 != m2.end(); it2++){m3[it1->first + it2->first] += it1->second * it2->second;}}cout.setf(ios_base::fixed, ios_base::floatfield);cout.precision(1);for (map<int, float>::iterator it = m3.begin(); it != m3.end(); it++){if (it->second == 0.0f)m3.erase(it);}cout << m3.size();for (map<int, float>::reverse_iterator it = m3.rbegin(); it != m3.rend(); it++){cout <<" "<< it->first << " " << it->second;}cout << endl;return 0;}



1009. Product of polynomials (25) -- Pat (Advanced Level) practise

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.