PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25
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
解题:
#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的更多相关文章
- 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 ...
- 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 ...
- 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, ...
- PAT (Basic Level) Practice 1002 写出这个数 分数 20
读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 10100. 输出格式: 在一行内输出 ...
- PAT (Basic Level) Practice 1005 继续(3n+1)猜想 分数 25
卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对 n=3 进行验证的时 ...
- PAT (Advanced Level) Practice 1001-1005
PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...
- PAT (Advanced Level) Practice(更新中)
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
随机推荐
- docker容器管理操作
Docker容器的四种状态: 运行 已暂停 重新启动 已退出 1.容器的创建 容器创建:就是将镜像加载到容器的过程. 创建容器时如果没有指定容器名称,系统会自动创建一个名称. 新创建的容器默认处于停止 ...
- Template -「平衡树」
Fhq-Treap. // Fhq-Treap const int MAXN = 1e5 + 5; struct Fhq_Treap { #define Lson Tr[p].l #define Rs ...
- html + css 01: 3d立方体
html + css实现3d立方体 css代码 /*页面背景色*/ body{ background-color: black; background-repeat:no-repeat; } /*** ...
- Blazor快速实现扫雷(MineSweeper)
如何快速的实现一个扫雷呢,最好的办法不是从头写,而是移植一个已经写好的! Blazor出来时间也不短了,作为一个.net开发者就用它来作吧.Blazor给我的感觉像是Angular和React的结合体 ...
- Odoo14 自定义widget小部件
不多说先上源码. 1 odoo.define('my_company_users_widget', function (require) { 2 "use strict"; 3 4 ...
- 趣味问题《寻人启事》的Python程序解决
偷懒了很久,今天我终于又来更新博客了~ 最近,我看到了一个趣味问题,或者说是数学游戏:<寻人启事>. 在表述这个问题前,我们需要了解一下"冰雹猜想": 对于任意一个正整 ...
- Visual Studio Code 中文设置教程
本文仅供学习交流使用,如侵立删!demo下载见文末 Pycharm中文设置教程 1.首先打开VisualStudioCode,点击扩展:extensions. 2.搜索chinese. 3.选择需要的 ...
- 青峰Flutter视频播放软件
下载地址: https://github.com/patton88/peak_flutter_player/raw/master/peak_flutter_player_v1.1.5_release0 ...
- 完成 DolphinScheduler 新手任务赢好礼活动 | 倒计时3 天
想轻松参与 DolphinScheduler 项目贡献吗? 想获得 500 元京东购物卡吗? 参与活动,有机会得更多活动奖励! 活动截止至6月30日 了解更多详情: 在你参与 DolphinSched ...
- LuoguP4719 【模板】动态 DP(动态DP,LCT)
\(n \times m\)的算法谁都会吧,注意到每次修改影响的仅是一部分的信息,因此可思考优化. 将每个节点对应一个矩阵\(\begin{bmatrix} g[v][0] & g[v][0] ...