PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏
1002. A+B for Polynomials (25)
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
#inc<span style="font-family: "Droid Sans Mono", Consolas, "Courier New", monospace; font-size: 1em; line-height: 1.5;">lu</span><span style="font-family: "Droid Sans Mono", Consolas, "Courier New", monospace; font-size: 1em; line-height: 1.5;">de<iostream></span>#include<cstring>
using namespace std; int main()
{
int i, k1, k2, j,max,count;
double a[5][1005], b[1005];
while (cin >> k1)
{
max = 0;
memset(a, 0, sizeof(a));
for (i = 0; i < k1; i++)
{
cin >> j;
cin >> a[0][j];
if (max < j)
max = j;
}
cin >> k2;
for (i = 0; i < k2; i++)
{
cin >> j;
cin >> a[1][j];
if (max < j)
max = j;
}
memset(b, 0, sizeof(b));
for (j = 0; j <= 1; j++)
{ for (i = 0; i <=max; i++)
{
b[i] += a[j][i];
}
}
count = 0;
for (i = 0; i <= max; i++)
{
if (b[i] != 0)
{
count++;
}
}
cout << count;
for (i = max; i >=0; i--)
{
if (b[i] != 0)
{
printf(" %d %.1f", i, b[i]);
}
}
cout << endl; }
return 0;
}
PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏的更多相关文章
- PAT甲 1007. Maximum Subsequence Sum (25) 2016-09-09 22:56 41人阅读 评论(0) 收藏
1007. Maximum Subsequence Sum (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- PAT甲 1006. Sign In and Sign Out (25) 2016-09-09 22:55 43人阅读 评论(0) 收藏
1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏
1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲 1048. Find Coins (25) 2016-09-09 23:15 29人阅读 评论(0) 收藏
1048. Find Coins (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves t ...
- PAT甲 1032. Sharing (25) 2016-09-09 23:13 27人阅读 评论(0) 收藏
1032. Sharing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To store Engl ...
- PAT甲 1029. Median (25) 2016-09-09 23:11 27人阅读 评论(0) 收藏
1029. Median (25) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given an incr ...
- PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏
1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏
1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...
随机推荐
- 如何判断int类型相等
int a=10: int b=10: a==b 通过==判断两个int值是否相等. if(a==b){ 相等 }else{ 不相等 }
- textbox显示定位到最后一行(最新一行)
this.textBox1.Select(this.txtMsgInfo.TextLength, 0); this.textBox1.ScrollToCaret();
- struts2 资源国际化
web.xml: <?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp ...
- 未能加载文件或程序集“AjaxControlToolkit”或它的某一个依赖项
对于这个问题,网上的解答都大同小异,最多的就是Bin文件夹下没有dll文件,引用路径问题.但我碰到的问题偏偏不是这个,而是没有一个人给出方法的问题.其实问题很简单,也很低级:IIS上发布网站的时候把整 ...
- Linux跑火车,提升趣味性
實現跑火車[可陶冶情操,愉悦心情]##下载yum源[root@localhost ~]# wget http://mirror.centos.org/centos/7/extras/x86_64/P ...
- Extjs Vbox布局方式,以及align种类,flex,pack属性含义简介
VBox布局方式,熟悉下一下几个主要属性: 一.align:字符类型,指示组件在容器内的对齐方式.这个是基于容器的左上角来排列的.pack不同,pack是根据容器的最上边来显示的. 1.left(默认 ...
- OC -网络请求 - NSURLConnection - GET
#import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDelegate> ...
- php使用数组语法访问对象
有一个对象,不过希望能用数组的语法来读写数据,可以使用 实现SPL的ArrayAccess接口来解决. 使用场景:加载配置文件类.larvel框架加载配置文件就这利用数组来操作对象. 数组式访问Obj ...
- discuz回贴通知插件实现-页面嵌入点(钩子)
1.如何保证主题被回复时业务代码被执行. 2.获得主题,主题发布者,贴子等信息. 3.discuz发送email邮件. discuz使用嵌入点(钩子)来处理代码的执行时机. 当用户开启插件开发者模 ...
- CSV 文件
CSV 文件 CSV(Comma Separated Values 逗号分隔值) 是一种文件格式(如.txt..doc等),也可理解 .csv 文件就是一种特殊格式的纯文本文件.即是一组字符序列,字符 ...