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 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
思路:
简单题目。注意格式。如果某一项系数为0,不输出。最后一种情况,没有存在项,输出"0\n"
源代码:
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- using namespace std;
- int main() {
- int na,nb;
- scanf("%d",&na);
- int flag[]={};
- double res[]={};
- int index;double data;
- for(int i=;i<na;++i) {
- scanf("%d %lf",&index,&data);
- flag[index]=;
- res[index]+=data;
- }
- scanf("%d",&nb);
- for(int i=;i<nb;++i) {
- scanf("%d %lf",&index,&data);
- flag[index]=;
- res[index]+=data;
- }
- int cnt=;
- for(int i=;i<=;++i) {
- if(flag[i]&&fabs(res[i])>1e-)
- cnt++;
- }
- if(cnt==) {
- printf("");
- } else {
- printf("%d ",cnt);
- }
- for(int i=;i>=;--i) {
- if(flag[i]&&fabs(res[i])>1e-) {
- printf("%d %.1lf",i,res[i]);
- cnt--;
- if(cnt==) {
- break;
- } else {
- printf(" ");
- }
- }
- }
- printf("\n");
- return ;
- }
PAT 1002. A+B for Polynomials (25) 简单模拟的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- PAT 甲级1002 A+B for Polynomials (25)
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 ...
- 【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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- eclipse中project facet问题
一般出现在从别处import的项目上,只有项目文件夹上有红叉,其他地方都正常,现总结个人的几个解决方案: 有几种可能: 1,编码设置是否一致,也即是你项目原来的编码和现在eclipse用的默认编码是否 ...
- Introduction of Git, Github and Gitlab
========================================================================== Version control is a syst ...
- 桌面消息通知:HTML5 Notification
先上一段完整代码 //注册权限 Notification.requestPermission(function (status) { // 这将使我们能在 Chrome/Safari 中使用 Noti ...
- Android 开发笔记___textvieww__跑马灯效果
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 从ELK到EFK演进
背景 作为中国最大的在线教育站点,目前沪江日志服务的用户包含网校,交易,金融,CCTalk 等多个部门的多个产品的日志搜索分析业务,每日产生的各类日志有好十几种,每天处理约10亿条(1TB)日志,热数 ...
- C 程序实现密码隐秘输入 linux系统可执行
读写用户输入,屏幕不回显 char *getpass( const char *prompt); getpass用于从键盘读取用户输入,但屏幕不回显. 参数prompt为屏幕提示字符. 函数返回值为用 ...
- 【机器学习实战】第14章 利用SVD简化数据
第14章 利用SVD简化数据 SVD 概述 奇异值分解(SVD, Singular Value Decomposition): 提取信息的一种方法,可以把 SVD 看成是从噪声数据中抽取相关特征.从生 ...
- Python概述与安装
Python 一门面向对象的解释性语言. Python优点 开发效率高(有丰富的各种类库,不需要重复造轮子):可移植性:解释性:免费开源:交互式(IDLE,代码写一行执行一行) Python缺点 相对 ...
- 开篇-我眼中的FPGA
既然是开篇,那就来闲话叨一叨FPGA吧. 掰掰指头,结识FPGA估计有5年多.作为嵌入式工程师,每天的日常充斥着ARM.DSP.操作系统.通讯.总线等耳熟能详的词汇,徜徉其中不能自拔,而这其中,自觉最 ...
- MySQL性能建议者mysqltuner.pl和pt-variable-advisor
[root@etch171 ~]# mysqltuner.pl --host >> MySQLTuner - Major Hayden <major@mhtx.net> > ...