【题目链接】

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的更多相关文章

  1. 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 ...

  2. 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. ...

  3. 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 ...

  4. PAT (Basic Level) Practise:1002. 写出这个数

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

  5. PAT (Basic Level) Practise:1040. 有几个PAT

    [题目链接] 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问一共可 ...

  6. PAT (Advanced Level) Practise 1002 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 ...

  7. 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 ...

  8. PAT (Basic Level) Practise:1032. 挖掘机技术哪家强

    [题目链接] 为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过105的正整数N,即参赛人数.随后N行 ...

  9. PAT (Advanced Level) Practise 1004 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...

随机推荐

  1. daydayup3 codeforces144C

    上古的c还是很简单的,一直逗比忘记加EOF了,直到看了数据才发现 题意:给你两个字符串a,b,求问字符串a里有多少个子串排列后可以生成字符串b,‘?’可以替换为任意小写字母 思路:统计第一个子字符串小 ...

  2. Cocopods不显示三方库的解决方法

    把 $(PODS_ROOT) 的字段添加到 User Header Search Paths 的文件路径下

  3. asp.net实现IHttpModule接口注意事项

    IHttpModule向实现类提供模块初始化和处置事件. IHttpModule包含兩個方法: public void Init(HttpApplication context);public voi ...

  4. Spring(2)

    Spring中的IOC和DI容器的概述 IOC(Inversion of control):其思想是反转资源获取的方向,传统的资源查找方式要求组件向容器发出请求查找资源作为回应,容器适时的返回资源 而 ...

  5. 不支持关键字“data source”

    网上大部分都是说data source之间需要插入一个空格或者都是一些低级的拼写错误造成的,但是我没有出现这些情况,是通过把data source改成server解决的,具体config里面的代码如下 ...

  6. C# dll加载,抽象方法的使用

    抽象类! dll的使用 /// <summary> /// 返回类型--插件 /// </summary> /// <param name="baseName& ...

  7. C++多线程1

    一个多线程的实例 #include "stdafx.h" #include <windows.h> DWORD __stdcall Func(LPVOID pm) { ...

  8. VS 工程的 输出路径和工作路径的区别

    输出路径,是vs编译项目生成可执行文件的路径:工作路径是环境变量,比如我们在程序中写相对路径,就是以这个路径为基础的.在默认情况下,输出路径和工作路径都不写的话,默认是程序的bin下面的debug或者 ...

  9. kendo ui之grid列表

    1.test_grid.jsp <html><head> <%@ include file="/WEB-INF/jsp/common/top.jsp" ...

  10. Linux网络编程的一般步骤(1)

    一.套接字的地址结构. IPV4套接字地址结构通常也称为"网际套接字地址结构",它以sockaddr_in 命名;POSIX定义如下: #include <stdio.h&g ...