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 ...
随机推荐
- [转载]Python 元组、列表、字典、文件
python的元组.列表.字典数据类型是很python(there python is a adjective)的数据结构.这些结构都是经过足够优化后的,所以如果使用好的话,在某些area会有很大的益 ...
- 用volley在Genymotion上获取网页源码
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdUAAALUCAIAAADSbz+YAAAgAElEQVR4nOydeVwT197/R+9zu9zluU
- Java集合类学习笔记(Queue集合)
Queue集合用于模拟队列(先进先出:FIFO)这种数据类型. Queue有一个Deque接口,代表一个"双端队列",双端队列可以同时从两端来添加.删除元素,因此Deque的实现类 ...
- 使用VisualVM进行性能分析及调优(转)
VisualVM 是一款免费的\集成了多个 JDK 命令行工具的可视化工具,它能为您提供强大的分析能力,对 Java 应用程序做性能分析和调优.这些功能包括生成和分析海量数据.跟踪内存泄漏.监控垃圾回 ...
- spring事务详解(转载+高亮)
spring提供的事务管理可以分为两类:编程式的和声明式的.编程式的,比较灵活,但是代码量大,存在重复的代码比较多:声明式的比编程式的更灵活.编程式主要使用transactionTemplate.省略 ...
- Jupyter notebook 配置目录
默认打开Jupyter notebook,工作目录是C:\Users\Username,这里面有很多其它与Jupyter notebook无关的文件,也很有用,不能看着烦就删掉,所以需要修改Jupyt ...
- python登录执行命令
#-*- coding: utf-8 -*- #!/usr/bin/python import paramiko import threading import getpass def ssh2(ip ...
- Android 完整开源应用,完整开源项目
(Antox)聊天的 (new) (OpenKeychain)OpenPGP在android上的实现 (new) (Flock)提供同步服务 (OpenFlappyBird)曾经火爆的 ...
- ubuntu安装谷歌输入法
1,sudo apt-get install fcitx-googlepinyin 2,在settings->Language Support里将keyboard input method sy ...
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
发布mvc遇到的HTTP错误 403.14-Forbidden解决办法 <system.webServer> <validationvalidateIntegratedMod ...