PAT (Advanced Level) Practise:1002. A+B for Polynomials
This time, you are supposed to find A+B where A and B are two polynomials.
Input
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
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(void)
{
float a[+];
float b[+];
int i, cnt;
int K, Nk;
float aNk; memset(a, , sizeof(a));
memset(b, , sizeof(b)); scanf("%d", &K);
for(i = ; i < K; i++)
{
scanf("%d %f", &Nk, &aNk);
a[Nk] = aNk;
}
scanf("%d", &K);
for(i = ; i < K; i++)
{
scanf("%d %f", &Nk, &aNk);
b[Nk] = aNk;
} cnt = ;
for(i = ; i < sizeof(a)/sizeof(a[]); i++)
{
a[i] = a[i] + b[i];
if(a[i] != 0.0)
cnt++;
} printf("%d", cnt);
for(i = sizeof(a)/sizeof(a[]) - ; i >= ; i--)
{
if(a[i] != )
printf(" %d %.1f", i, a[i]);
} return ;
}
PAT (Advanced Level) Practise:1002. A+B for Polynomials的更多相关文章
- PAT (Advanced Level) Practise:1001. A+B Format
[题目链接] Calculate a + b and output the sum in standard format -- that is, the digits must be separate ...
- PAT (Advanced Level) Practise:1027. Colors in Mars
[题目链接] People in Mars represent the colors in their computers in a similar way as the Earth people. ...
- PAT (Advanced Level) Practise:1008. Elevator
[题目链接] The highest building in our city has only one elevator. A request list is made up with N posi ...
- PAT (Basic Level) Practise:1002. 写出这个数
[题目链接] 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式:在一行内输出n的各 ...
- PAT (Basic Level) Practise:1040. 有几个PAT
[题目链接] 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问一共可 ...
- PAT (Advanced Level) Practise 1002 解题报告
GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 ...
- PAT (Advanced Level) Practise - 1094. The Largest Generation (25)
http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...
- PAT (Basic Level) Practise:1032. 挖掘机技术哪家强
[题目链接] 为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过105的正整数N,即参赛人数.随后N行 ...
- PAT (Advanced Level) Practise 1004 解题报告
GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...
随机推荐
- CALayer 3 详解 -----转自李明杰
CALayer3-层的属性 本文目录 一.隐式动画属性 二.position和anchorPoint 回到顶部 一.隐式动画属性 * 在前面几讲中已经提到,每一个UIView内部都默认关联着一个C ...
- Android Token的使用学习
学习Token Token是什么? Token是服务端生成的一串字符串,以作客户端进行请求的一个令牌,当第一次登录后,服务器生成一个Token便将此Token返回给客户端,以后客户端只需带上这个Tok ...
- Windows 7下硬盘安装Ubuntu 14.04图文教程
http://www.linuxidc.com/Linux/2014-04/100369.htm
- 更新App版本的流程
上班一年了还没有自己打包上传过APP,周五下班时项目经理手把手教了我一遍,我大致把流程在这里回顾一下: 1.首先要将svn上的代码拷贝一份到分支上,用终端操作:svn cp https://192.1 ...
- 利用CSOM向列表添加文件夹
博客地址:http://blog.csdn.net/FoxDave 本文只为记录一下这个小细节,不会过多赘述,开发可以看懂. 如果想向一个列表或库中添加文件夹,平时我们自然想到的是list.ro ...
- 自顶而下设计FPGA
对IC设计而言,FPGA设计层级大致包括:系统级和行为级,RTL级,门级和晶体管级.然而更普遍的情况,FPGA只是用作实时数据采集控制.某些快速处理算法.PCIe\DDR3等高速数据通道,甚至某些简单 ...
- JAVA学习心得
学习JAVA一个学期了,虽然学的不是很好,也没有彻底理解JAVA的真正内涵,但是我认为学习java应该是循环渐进,有始有终,按部就班,脚踏实地.java是一门有着阶梯性的一门语言,信心,恒心,毅力是最 ...
- 学习NSRulerView
NSRulerMarker 有个imageOrigin是描述Marker中image的位置的: 在horizontal的ruler中,imageOrigin的x坐标是跟marker的location进 ...
- Typescript中的class interface 只是在声明,其实什么也没有干!
由于vue.js的特殊机制,初始化后给对象添加的属性是无法更新UI的. 最近结合typescript和vue进行web开发,就遇到了这样的坑. class user{ name:string; age ...
- 团队第二周:SRS文档
项目计划: 对于这次的实验,我们组计划进行一个图书管理系统的项目书写,在第一阶段,对该项目先进行一下规划,总结该项目的注意事项以及实验要求,并加以实施. 下面我先对我们项目的要求坐一下说明: 1定义五 ...