课本AC代码

#include <cstdio>
struct Poly {
int exp;//指数
double cof;
} poly[1001];//第一个多项式 double ans[2001];//存放结果
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n, m, number = 0;
scanf("%d", &n);//第一个多项式中非零系数的项数
for(int i = 0; i < n; i++) {
scanf("%d %lf", &poly[i].exp, &poly[i].cof);//第一个多项式的指数和系数
}
scanf("%d", &m);//第二个多项式中非零系数的项数
for(int i = 0; i < n; i++) {
int exp;
double cof;
scanf("%d%lf", &exp, &cof); //第二个多项式的指数和系数
for(int j = 0; j < n; j++) {//与第一个多项式中的每一项相乘
ans[exp + poly[j].exp] += (cof * poly[i].cof);
}
}
for(int i = 0; i <= 2000; i++) {
if(ans[i] != 0.0) number++; //累计非零系数的项数
}
printf("%d", number);
for(int i = 2000; i >= 0; i--) { //输出
if(ans[i] != 0.0) {
printf(" %d %.1f", i, ans[i]);
}
}
return 0;
}

自己代码,调试还总是出错

#include <cstdio>
#include <algorithm>
const int max_n = 2100; using namespace std; double p1[max_n][2] = {0.0}, product[max_n] = {0.0};
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n1 = 0, n2 = 0, big = 0;
scanf("%d", &n1);
for(int i = 0; i < n1; i++) {
int cof;
double exp;
scanf("%d %1f", &cof, &exp);//p1[i][0]:系数, p1[i][1]:指数
p1[cof] += exp;
}
/*for(int i = 0; i < n1; i++) {
printf("1: %d %1f \n\n", p2[i], p1[i]);//p1[i][0]:系数, p1[i][1]:指数
}
scanf("%d", &n2);
for(int i = 0; i < n2; i++) {
int cof;
double exp;
scanf("%d %1f", &cof, &exp);//p2[i][0]:系数, p2[i][1]:指数
for(int j = 0; j < n1; j++) {
for(int i = 0; i < 1010; i++) {
product[exp +
}
/*for(int i = 0; i < n1; i++) {
printf("2: %d %1f \n\n", p4[i], p3[i]);//p1[i][0]:系数, p1[i][1]:指数
}
for(int i = 0; i < n2; i++) {
for(int j = 0; i < n1; j++) {
p5[p2[i] + p4[i]] += (p1[i] * p3[i]);
}
}
int num = 0;
for(int i = 0; i <= max_n; i++) {
if(p5[i] != 0.0) num++;
}
printf("%d", num);
for(int i = max_n; i > 0; i--) {
if(p5[i] != 0.0) {
printf(" %d %1f", i, p5[i]);
}
}
return 0;
}

PAT A1009 Product of Polynomials(25)的更多相关文章

  1. A1009 Product of Polynomials (25)(25 分)

    A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...

  2. PAT 1009 Product of Polynomials (25分) 指数做数组下标,系数做值

    题目 This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: E ...

  3. PAT A1009 Product of Polynomials (25 分)——浮点,结构体数组

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  4. PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  5. PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

  6. pat 甲级 1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  7. pat1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  8. PATA 1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  9. 1009 Product of Polynomials (25分) 多项式乘法

    1009 Product of Polynomials (25分)   This time, you are supposed to find A×B where A and B are two po ...

随机推荐

  1. 《30天自制操作系统》学习笔记--Mac环境搭建

    弄了三天了,终于弄好了,先说结果,就是作者在网站上放了os x的工具(hrb.osask.jp,也有linux下的工具,可以自己去下载),也就是说我白忙活了三天... 再说一下这几天都干啥了,主要是想 ...

  2. P1359 租用游艇 && P3905 道路重建 ------Floyd算法

    P1359 租用游艇   原题链接https://www.luogu.org/problemnew/show/P1359 P3905 道路重建   原题链接https://www.luogu.org/ ...

  3. MongoDB系列一:MongoDB文档型数据库特点介绍

    一.MongoDB数据库的存储特点: 1.MongoDB是文档型数据库,存储的是文档(将json二进制化为Bson存储): 2.存储的每篇文档都可以有自己独特的存储结构,颠覆了传统数据库必须按照表和列 ...

  4. dos切换其他目录加参数/D

    D:\>cd /D c:\Windows c:\Windows> 不加参数/D 无法切换到另一个盘符

  5. Linux设备驱动程序 之 字符设备的注册

    内核内部使用struct cdev结构来标识字符设备,在内核调用设备的操作之前,必须分配并注册一个或者多个上述结构,为此,我们的代码需要包含<linux/cdev.h>,其中定义了这个结构 ...

  6. Qt Model/View 的简单说明

    目录: (一) Qt Model/View 的简单说明 .预定义模型 (二)使用预定义模型 QstringListModel例子 (三)使用预定义模型QDirModel的例子 (四)Qt实现自定义模型 ...

  7. kafka可视化工具安装及简单使用

    一.安装 双击kafkatool_64bit.exe安装kafka可视化工具,并且C:\Windows\System32\drivers\etc配置HOSTS,打开HOSTS并添加: HOSTS添加: ...

  8. QQ输入法中英文标点符号快速切换

    QQ输入法中英文标点符号快速切换 全角半角切换 shift+ Space 全角半角切换 双击shift 中英文标点符号快速切换   Ctrl+.

  9. ApkUtils

    import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo ...

  10. android Api操作SQLite数据库的示例代码

    import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.databa ...