zoukankan      html  css  js  c++  java
  • PAT:1009. Product of Polynomials (25) AC

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    //【warning】double 输入%lf,输出%f
    struct arr
    {
      int exp;      //指数
      double cof;      //系数
    }arr[1005];
    double ans[2010];    //下标是指数,内容是系数
    int main()
    {
      memset(arr,0,sizeof(arr));
      memset(ans,0,sizeof(ans));
      int n,m;
      scanf("%d",&n);          //第一个多项式n项
      for(int i=0 ; i<n ; ++i)
      {
        scanf("%d %lf",&arr[i].exp,&arr[i].cof);
      }
      scanf("%d",&m);
      for(int i=0 ; i<m ; ++i)
      {
        int exp;          //第二个多项式指数
        double cof;          //第二个多项式系数
        scanf("%d %lf",&exp,&cof);
        for(int j=0 ; j<n ; ++j)
        {
          ans[exp+arr[j].exp]+=cof*arr[j].cof;    //指数相加,系数相乘,存入相应指数的系数数组中
        }
      }
      int num=0;
      for(int i=0 ; i<2010 ; ++i)        //统计项数  
        if(ans[i]!=0)
          ++num;
      printf("%d",num);
      for(int i=2009 ; i>=0 ; --i)      //【warning】ans数组2010个元素,下标最多到2009
      {
        if(ans[i]!=0)
        {
          printf(" %d %.1f",i,ans[i]);
        }
      }
      //system("pause");
      return 0;
    }
  • 相关阅读:
    进程与线程的区别
    开启线程的两种方式
    线程
    生产者消费者模型(重要)
    队列
    互斥锁
    守护进程(了解)
    Process对象的其它方法与属性(join)
    僵尸进程与孤儿进程
    Servlet
  • 原文地址:https://www.cnblogs.com/Evence/p/4295657.html
Copyright © 2011-2022 走看看