PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25
2024-08-30 21:22:57
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]);
}
}
}
最新文章
- ORACLE 中的 ROW_NUMBER() OVER() 分析函数的用法
- 在linux命令行中直接执行php命令
- Android:Android SDK Manager顺利下载
- FTP软件Filezilla出现“读取目录列表失败”的解决办法
- 初识ege图形库
- WinForm 小程序 NotePad
- maven 打包 时出现非法字符: /65279错误
- 基于vue与vux做的可滑动tab组件(附源码)
- CSipIm断网重连崩溃原因分析
- 洛谷P1274-魔术数字游戏
- 搭建SpringBoot+dubbo+zookeeper+maven框架(四)
- 构造方法关键字---this
- 2018/09/17《涂抹MySQL》【性能优化及诊断】学习笔记(七)
- docker之私有仓库镜像管理
- ABAP基础二:ALV基础之ALV的简单编辑
- Spring框架中Bean管理的常用注解
- Spring MVC深入讲解
- 图像处理之FPN校正
- mysql c语言 动态链接库
- 禁止 git 自动转换换行符
热门文章
- Solution -「CF645F」Cowslip Collections
- harbor之HTTPS安装
- 【Azure 事件中心】Azure Event Hub 新功能尝试 -- 异地灾难恢复 (Geo-Disaster Recovery)
- 基于SqlSugar的开发框架循序渐进介绍(13)-- 基于ElementPlus的上传组件进行封装,便于项目使用
- InvalidClassException异常_原理和解决方案和练习_序列化集合
- HMS Core Discovery第16期回顾|与虎墩一起,玩转AI新“声”态
- 青山不遮,毕竟东流,集成Web3.0身份钱包MetaMask以太坊一键登录(Tornado6+Vue.js3)
- 利用MySQL Router构建读写分离MGR集群
- Linux 域名和DNS
- Linux —用户和组