This time, you are supposed to find A+B where A and B are two polynomials.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:

K N1​ aN1​​ N2​ aN2​​ ... NK​ aNK​​

where K is the number of nonzero terms in the polynomial, Ni​ and aNi​​ (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10,0≤NK​<⋯<N2​<N1​≤1000.

Output Specification:

For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

Sample Input:

2 1 2.4 0 3.2
2 2 1.5 1 0.5
 

Sample Output:

3 2 1.5 1 2.9 0 3.2
 
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
 

解题:

#include<stdio.h>
#include<string.h> int main()
{
int k,i,j,l,c=0;
int temp[1001];
int flag=1;
float arr1[1001],arr2[1001],temparr[1001];
memset(arr1,0,sizeof(arr1));
memset(arr2,0,sizeof(arr2));
memset(temparr,0,sizeof(temparr));
memset(temp,1001,sizeof(temp));
scanf("%d ",&k);
for(i=0;i<k;i++)
{
scanf("%d ",&j);
for(l=0;l<k;l++){
if(temp[l]==j)
{
scanf("%f ",&temparr[j]);
arr1[j]+=temparr[j];
flag=0;
}
}
if(flag==1)
{
temp[i]=j;
scanf("%f ",&arr1[j]);
}
flag=1;
}
//printf("%d %d %.1f",k,j,arr1[1]);
scanf("%d ", &k);
for(i=0;i<k;i++)
{
scanf("%d ",&j);
for(l=0;l<k;l++){
if(temp[l]==j)
{
scanf("%f ",&temparr[j]);
arr2[j]+=temparr[j];
flag=0;
}
}
if(flag==1)
{
temp[i]=j;
scanf("%f ",&arr2[j]);
}
flag=1;
} for(i=0;i<12;i++)
{
arr1[i]=arr1[i]+arr2[i];
}
for(i=0;i<12;i++)
{
if(arr1[i]!=0)
{
c++;
}
}
printf("%d",c);
for(i=12;i>=0;i--)
{
if(arr1[i]!=0)
{
printf(" %d %.1f",i,arr1[i]);
}
}
}
 

最新文章

  1. ORACLE 中的 ROW_NUMBER() OVER() 分析函数的用法
  2. 在linux命令行中直接执行php命令
  3. Android:Android SDK Manager顺利下载
  4. FTP软件Filezilla出现“读取目录列表失败”的解决办法
  5. 初识ege图形库
  6. WinForm 小程序 NotePad
  7. maven 打包 时出现非法字符: /65279错误
  8. 基于vue与vux做的可滑动tab组件(附源码)
  9. CSipIm断网重连崩溃原因分析
  10. 洛谷P1274-魔术数字游戏
  11. 搭建SpringBoot+dubbo+zookeeper+maven框架(四)
  12. 构造方法关键字---this
  13. 2018/09/17《涂抹MySQL》【性能优化及诊断】学习笔记(七)
  14. docker之私有仓库镜像管理
  15. ABAP基础二:ALV基础之ALV的简单编辑
  16. Spring框架中Bean管理的常用注解
  17. Spring MVC深入讲解
  18. 图像处理之FPN校正
  19. mysql c语言 动态链接库
  20. 禁止 git 自动转换换行符

热门文章

  1. Solution -「CF645F」Cowslip Collections
  2. harbor之HTTPS安装
  3. 【Azure 事件中心】Azure Event Hub 新功能尝试 -- 异地灾难恢复 (Geo-Disaster Recovery)
  4. 基于SqlSugar的开发框架循序渐进介绍(13)-- 基于ElementPlus的上传组件进行封装,便于项目使用
  5. InvalidClassException异常_原理和解决方案和练习_序列化集合
  6. HMS Core Discovery第16期回顾|与虎墩一起,玩转AI新“声”态
  7. 青山不遮,毕竟东流,集成Web3.0身份钱包MetaMask以太坊一键登录(Tornado6+Vue.js3)
  8. 利用MySQL Router构建读写分离MGR集群
  9. Linux 域名和DNS
  10. Linux —用户和组