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]);
}
}
}
 

PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25的更多相关文章

  1. PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...

  2. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...

  3. PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) (排序)

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  4. PAT (Basic Level) Practice 1002 写出这个数 分数 20

    读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 10100. 输出格式: 在一行内输出 ...

  5. PAT (Basic Level) Practice 1005 继续(3n+1)猜想 分数 25

    卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对 n=3 进行验证的时 ...

  6. PAT (Advanced Level) Practice 1001-1005

    PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...

  7. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

  8. PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...

  9. PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...

随机推荐

  1. 图的存储结构大赏------数据结构C语言(图)

    图的存储结构大赏------数据结构C语言(图) 本次所讲的是常有的四种结构: 邻接矩阵 邻接表 十字链表 邻接多重表 邻接矩阵 概念 两个数组,一个表示顶点的信息,一个用来表示关联的关系. 如果是无 ...

  2. C++ 弹幕游戏

    可能会持续更新吧,, 我们说一下固定弹,直线轨迹的做法 . 首先放一个 Kaguya 的波粒: 境符「波与粒的境界」 since C++98,系统要求 Windows . #include <c ...

  3. PHP几个工具函数

    移除XSS攻击脚本 function RemoveXSS($val) { // remove all non-printable characters. CR(0a) and LF(0b) and T ...

  4. YII容器类依赖注入

    程序 = 算法 + 数据结构 数据结构 制约了 算法的===>>>>依赖注入 依赖注入也就是解数据结构和算法耦合的思想 <?php /** * Created by Ph ...

  5. LyScript 实现对内存堆栈扫描

    LyScript插件中提供了三种基本的堆栈操作方法,其中push_stack用于入栈,pop_stack用于出栈,而最有用的是peek_stack函数,该函数可用于检查指定堆栈位置处的内存参数,利用这 ...

  6. Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。

    前言: Taurus.MVC 微服务版本已经发布了:Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单. 以前都是框架发布时写点相关功能点的文章,没有形成 ...

  7. 6. MGR状态监控 | 深入浅出MGR

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 目录 1. 节点状态监控 2. MGR事务状态监控 3. 其他监控 4. 小结 参考资料.文档 免责声明 文章推荐: 关于 ...

  8. java的stream让我灵光一现

    说实话,我是一个到了退役也没有搞明白C++的istream和ostream的. 刚开始的时候我把<iostream>直接拆解成ios和tream 真,果粉暴露 退役之后划水,倒是从java ...

  9. jsp获取多选框组件的值

    jsp获取多选框组件的值 1.首先写一个带有多选框的前台页 1 <%@ page language="java" contentType="text/html; c ...

  10. iOS影视应用+全网视频下载

    又一个新的iOS影视伪装 打开软件连续点击3次列表,然后关闭重新打开即可变身,无广告全免费高画质,还有电视直播 下载地址:https://apps.apple.com/cn/app/贴画壁纸/id16 ...