zoukankan      html  css  js  c++  java
  • 1002. A+B for Polynomials (25)

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 const int maxn = 10005;
     7 double a[maxn];
     8 int b[maxn];
     9 double c[maxn];
    10 
    11 int main(){
    12     ios::sync_with_stdio(false);
    13     int k;
    14     cin >> k;
    15     int x;
    16     double y;
    17     int Max = 0;
    18     for (int i = 1; i <= k; i++){
    19         cin >> x >> y;
    20         a[x] += y;
    21         if (Max < x)
    22             Max = x;
    23     }
    24     int k1;
    25     cin >> k1;
    26     for (int i = 1; i <= k1; i++){
    27         cin >> x >> y;
    28         a[x] += y;
    29         if (Max < x)
    30             Max = x;
    31     }
    32     int ans = 0;
    33     for (int i = Max; i >= 0; i--){
    34         if (a[i] == 0) continue;
    35         b[ans] = i;
    36         c[ans++] = a[i];
    37     }
    38     cout << ans;
    39     for (int i = 0; i < ans; i++){
    40         printf(" %d %.1lf", b[i], c[i]);
    41         //cout << " " << b[i] << " " << c[i];
    42     }
    43     //最后一行没有空格(包括换行)
    44     //cout << endl;
    45     system("pause");
    46     return 0;
    47 }
  • 相关阅读:
    素数算法问题
    字符指针和字符数组
    指针引用多维数组
    指针细节整理3
    指针细节整理2
    指针细节整理
    公约数和公倍数
    冒泡排序、选择排序
    如何写出高性能的sql语句?
    并发控制
  • 原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/8680921.html
Copyright © 2011-2022 走看看