PAT (Advanced Level) 1002. A+B for Polynomials (25)

为0的不要输出。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

double a[1500],b[1500];
int k;

int main()
{
    for(int i=0;i<=1000;i++) a[i]=b[i]=0;
    int Max=-1;
    scanf("%d",&k);
    for(int i=1;i<=k;i++)
    {
        int id;double num;
        scanf("%d%lf",&id,&num);
        Max=max(Max,id);
        a[id]=num;
    }

    scanf("%d",&k);
    for(int i=1;i<=k;i++)
    {
        int id;double num;
        scanf("%d%lf",&id,&num);
        Max=max(Max,id);
        b[id]=num;
    }

    int cnt=0;
    for(int i=Max;i>=0;i--)
        if(a[i]+b[i]!=0) cnt++;

    printf("%d",cnt);
    int op=0;
    for(int i=Max;i>=0;i--)
    {
        if(a[i]+b[i]!=0){
            printf(" %d %.1lf",i,a[i]+b[i]);
        }
    }
    return 0;
}
时间: 2024-10-07 10:13:53

PAT (Advanced Level) 1002. A+B for Polynomials (25)的相关文章

PAT (Advanced Level) 1055. The World&#39;s Richest (25)

排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using names

PAT (Advanced Level) 1082. Read Number in Chinese (25)

模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std;

PAT (Advanced Level) 1039. Course List for Student (25)

map会超时,二分吧... #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<vector> using namespace std; int n,m; int

PAT (Advanced Level) 1102. Invert a Binary Tree (25)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; struct Node { int left; int right; }s[20]; int

PAT (Advanced Level) 1098. Insertion or Heap Sort (25)

简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; const int maxn=200; int a[maxn],b[m

PAT (Advanced Level) 1066. Root of AVL Tree (25)

AVL树的旋转.居然1A了.... 了解旋转方式之后,数据较小可以当做模拟写. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using name

PAT (Advanced Level) 1067. Sort with Swap(0,*) (25)

只对没有归位的数进行交换. 分两种情况: 如果0在最前面,那么随便拿一个没有归位的数和0交换位置. 如果0不在最前面,那么必然可以归位一个数字,将那个数字归位. 这样模拟一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include

1002. A+B for Polynomials (25)——PAT (Advanced Level) Practise

题目信息: 1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file contains one test case. Each case occupies 2 lin

Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)

Pat1043代码 题目描述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes