课本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;
}

最新文章

  1. JS 的事件委托机制
  2. vim 空格 制表符
  3. iOS开发零基础--Swift篇:逻辑分支
  4. 深入探索Android中的Handler
  5. Eclipse启动认定SDK地址,出现Error executing aapt
  6. 高效的Nginx
  7. Edit显示行号
  8. wcf简单的创建和运用
  9. error C2143 &amp; error C4430
  10. linux相关小工具的使用(一)————代码相关工具
  11. python测试框架--nose
  12. C# 线程同步之排它锁/Monitor监视器类
  13. mysql、sqlserver数据库常见数据类型对应java中的的类型探究
  14. wordpress-标签
  15. Linux下查询进程PS或者杀死进程kill的小技巧
  16. 利用Filter和拦截器,将用户信息动态传入Request方法
  17. API做翻页的两种思路
  18. HttpServletRequest内容处理工具类
  19. Spring的AOP基于AspectJ的注解方式开发2
  20. IdentityServer4【Topic】之登陆注册

热门文章

  1. Java面向对象5(V~Z)
  2. Palindrome Degree(CodeForces 7D)—— hash求回文
  3. AT3912 Antennas on Tree
  4. ORA-28000
  5. log4j.properties log4j.xml 路径问题
  6. Leetcode题目198.打家劫舍(动态规划-简单)
  7. webpack入门-配置项
  8. L1-049 天梯赛座位分配 (20 分)
  9. mysql连表操作是先连表还是先查询条件
  10. centos7 下设置 mongodb 开机启动 (重点)