zoukankan      html  css  js  c++  java
  • 【PAT甲级】1002 A+B for Polynomials (25 分)

    题意:给出两个多项式,计算两个多项式的和,并以指数从大到小输出多项式的指数个数,指数和系数。

    AAAAAccepted code:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 double a[1007];
     4 int main(){
     5     int k;
     6     cin>>k;
     7     int max_n=0;
     8     for(int i=1;i<=k;++i){
     9         int n;
    10         cin>>n;
    11         double x;
    12         cin>>x;
    13         a[n]+=x;
    14         max_n=max(max_n,n);
    15     }
    16     cin>>k;
    17     for(int i=1;i<=k;++i){
    18         int n;
    19         cin>>n;
    20         double x;
    21         cin>>x;
    22         a[n]+=x;
    23         max_n=max(max_n,n);
    24     }
    25     int cnt=0;
    26     for(int i=0;i<=max_n;++i)
    27         if(a[i])
    28             cnt++;
    29     cout<<cnt;
    30     for(int i=max_n;i>=0;--i)
    31         if(a[i])
    32             printf(" %d %.1f",i,a[i]);
    33     return 0;
    34 }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    firefox 插件开发2
    android ndk
    android Fragment.
    排序算法
    php中判断iphone版本
    php css
    ndk 入门实例
    howtoaddabuttontopreferencescreen 自定义view
    分布式K/V存储方案
    android版 eclipse
  • 原文地址:https://www.cnblogs.com/ldudxy/p/11191597.html
Copyright © 2011-2022 走看看