当前位置:网站首页>PAT1009

PAT1009

2022-08-09 11:09:00 AlanLiu6

https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344

#include<cstdio>


double num[1005],ans[2005];

int main()
{
    int k;
    scanf("%d",&k);
    while(k--)
    {
        int x;
        double y;
        scanf("%d %lf",&x,&y);
        num[x] = y;
    }
    scanf("%d",&k);
    while(k--)
    {
        int x;
        double y;
        scanf("%d %lf",&x,&y);
        for(int i = 0;i < 1005;i++)
        {
            ans[x+i] += num[i]*y;
        }
    }
    int len = 0;
    for(int i = 0;i < 2005;i++)
        if(ans[i] != 0.0) len++;
    printf("%d",len);
    for(int i = 2005;i >=0 ;i--)
    {
        if(ans[i] != 0.0) printf(" %d %.1lf",i,ans[i]);
    }
    printf("\n");

    return 0;
}

原网站

版权声明
本文为[AlanLiu6]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Alen666/article/details/97710641