1002. A+B for Polynomials (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

  1. 2 1 2.4 0 3.2
  2. 2 2 1.5 1 0.5

Sample Output

  1. 3 2 1.5 1 2.9 0 3.2

思路:

简单题目。注意格式。如果某一项系数为0,不输出。最后一种情况,没有存在项,输出"0\n"

源代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. using namespace std;
  5. int main() {
  6. int na,nb;
  7. scanf("%d",&na);
  8. int flag[]={};
  9. double res[]={};
  10. int index;double data;
  11. for(int i=;i<na;++i) {
  12. scanf("%d %lf",&index,&data);
  13. flag[index]=;
  14. res[index]+=data;
  15. }
  16. scanf("%d",&nb);
  17. for(int i=;i<nb;++i) {
  18. scanf("%d %lf",&index,&data);
  19. flag[index]=;
  20. res[index]+=data;
  21. }
  22. int cnt=;
  23. for(int i=;i<=;++i) {
  24. if(flag[i]&&fabs(res[i])>1e-)
  25. cnt++;
  26. }
  27. if(cnt==) {
  28. printf("");
  29. } else {
  30. printf("%d ",cnt);
  31. }
  32. for(int i=;i>=;--i) {
  33. if(flag[i]&&fabs(res[i])>1e-) {
  34. printf("%d %.1lf",i,res[i]);
  35. cnt--;
  36. if(cnt==) {
  37. break;
  38. } else {
  39. printf(" ");
  40. }
  41. }
  42. }
  43. printf("\n");
  44. return ;
  45. }

PAT 1002. A+B for Polynomials (25) 简单模拟的更多相关文章

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

  2. PAT 1002 A+B for Polynomials (25分)

    题目 This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: E ...

  3. PAT 1002 A+B for Polynomials(map模拟)

    This time, you are supposed to find A+B where A and B are two polynomials(多项式). Input Each input fil ...

  4. PAT 甲级1002 A+B for Polynomials (25)

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

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

  6. 【PAT】1002. A+B for Polynomials (25)

    1002. A+B for Polynomials (25) This time, you are supposed to find A+B where A and B are two polynom ...

  7. PAT甲级 1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  8. PAT甲 1002. A+B for Polynomials (25) 2016-09-09 22:50 64人阅读 评论(0) 收藏

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  9. 1002 A+B for Polynomials (25)(25 point(s))

    problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...

随机推荐

  1. eclipse中project facet问题

    一般出现在从别处import的项目上,只有项目文件夹上有红叉,其他地方都正常,现总结个人的几个解决方案: 有几种可能: 1,编码设置是否一致,也即是你项目原来的编码和现在eclipse用的默认编码是否 ...

  2. Introduction of Git, Github and Gitlab

    ========================================================================== Version control is a syst ...

  3. 桌面消息通知:HTML5 Notification

    先上一段完整代码 //注册权限 Notification.requestPermission(function (status) { // 这将使我们能在 Chrome/Safari 中使用 Noti ...

  4. Android 开发笔记___textvieww__跑马灯效果

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  5. 从ELK到EFK演进

    背景 作为中国最大的在线教育站点,目前沪江日志服务的用户包含网校,交易,金融,CCTalk 等多个部门的多个产品的日志搜索分析业务,每日产生的各类日志有好十几种,每天处理约10亿条(1TB)日志,热数 ...

  6. C 程序实现密码隐秘输入 linux系统可执行

    读写用户输入,屏幕不回显 char *getpass( const char *prompt); getpass用于从键盘读取用户输入,但屏幕不回显. 参数prompt为屏幕提示字符. 函数返回值为用 ...

  7. 【机器学习实战】第14章 利用SVD简化数据

    第14章 利用SVD简化数据 SVD 概述 奇异值分解(SVD, Singular Value Decomposition): 提取信息的一种方法,可以把 SVD 看成是从噪声数据中抽取相关特征.从生 ...

  8. Python概述与安装

    Python 一门面向对象的解释性语言. Python优点 开发效率高(有丰富的各种类库,不需要重复造轮子):可移植性:解释性:免费开源:交互式(IDLE,代码写一行执行一行) Python缺点 相对 ...

  9. 开篇-我眼中的FPGA

    既然是开篇,那就来闲话叨一叨FPGA吧. 掰掰指头,结识FPGA估计有5年多.作为嵌入式工程师,每天的日常充斥着ARM.DSP.操作系统.通讯.总线等耳熟能详的词汇,徜徉其中不能自拔,而这其中,自觉最 ...

  10. MySQL性能建议者mysqltuner.pl和pt-variable-advisor

    [root@etch171 ~]# mysqltuner.pl --host >> MySQLTuner - Major Hayden <major@mhtx.net> > ...