PAT甲级1002 多项式相加
题目
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<iostream>
using namespace std;
int main(){float c[1001]={0};// zuida 2 you 3ge shuint k,m,n;float a;//if n= axiang+scanf("%d",&k);for(int i=0;i<k;i++){scanf("%d%f",&n,&a);c[n]+=a;} scanf("%d",&m);for(int i=0;i<m;i++){scanf("%d%f",&n,&a);c[n]+=a;} int count=0;for(int i=0;i<1001;i++){if(c[i]!=0) count++;}printf("%d",count);for(int i=1000;i>=0;i--){if(c[i]!=0.0){printf(" %d %0.1f",i,c[i]);}}return 0;
}
这里犯得错是printf的格式有问题
PAT甲级1002 多项式相加相关推荐
- PAT甲级1002 A+B for Polynomials:[C++题解]字符串、多项式加法或高精度加法
文章目录 题目分析 题目链接 题目分析 本题数据范围是1000 ,可以开一个数组 X [ ] ,X[i ]表示多项式中次幂是i的系数是多少. 因此,本题可以开两个数组,对应相加,然后输出非零项即可. ...
- PAT甲级 1002
PAT 甲级 1002 题目描述:多项式求和问题 输入两个多项式,输出和的多项式(多项式按指数递减排列) Sample Input: 2 1 2.4 0 3.2 2 2 1.5 1 0.5 Sampl ...
- Pat甲级 1002 A+B for Polynomials
Pat甲级 1002 A+B for Polynomials 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems ...
- PAT 甲级 1002
多项式加法 两处需要注意的: 相加后的多项式的系数如果是0,就不能输出 注意C++输出的格式 #include <bits/stdc++.h> using namespace std;st ...
- 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: Each ...
- PAT甲级1009 多项式相乘
题目 This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: E ...
- PAT甲级1002 All Roads Lead to Rome
All Roads Lead to Rome (30) 时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 Inde ...
- PAT甲级1009 Product of Polynomials:[C++题解]多项式乘法、高精度乘法
文章目录 题目分析 题目链接 题目分析 多项用一个数组来表示,数组下标表示多项式的次幂,存的内容表示多项式的系数. 然后用两重循环来计算多项式的乘法: for i : 第二个式子for j:第一个式子 ...
- PAT甲级训练合集(1-70)
本章题解跳转 考点 P1001 数字的数组表示和处理 P1002 多项式的数组表示和处理 P1003 深度优先搜素 P1004 深度优先搜素 P1005 哈希表 P1006 P1007 数组子区间求和 ...
最新文章
- [译]ASP.NET Core 2.0 部分视图
- HDOJ 1202 The calculation of GPA
- IK分词源代码分析学习——与solr4.0接口
- 清华大学计算机系毕业季博论 | 预荐未来的自己
- 解决 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- linux的技术点,给你的Linux系统上点stress
- 中路径查找器的功能_还在用路径查找器?试试它吧!
- SQL Server Alwayson架构下 服务器 各虚拟IP漂移监控告警的功能实现 -1(服务器视角)...
- 文件夹缩写(文件夹空格问题解决)
- 硅谷之谜读后感以及最近总结
- java后端开发项目流程_Java项目——后端笔记
- python 方差齐性检验_SPSS方差齐性检验(图文+视频教程)
- FLASH透明背景代码大全
- mysql5.7卸载教程_MySQL 5.7.19 简易安装、卸载教程
- 使用JRE8构建Java8基础镜像
- 1154 Vertex Coloring
- 计算机网络各层设备及功能讲解大汇总~
- 从拉马努金到张益唐——数学是一个整体
- 【深入Java虚拟机】之七:Javac编译与JIT编译
- linux xunsou_Linux 之 xunsearch
热门文章
- pytorchgpu测试_pytorch学习(十)—训练并测试CNN网络
- ajax如何提交多表单的值_菜狗教程-03-如何解决快速提交两次重复提交表单的问题...
- Qt保留小数点后两位
- SQL Server 2014 新建数据库
- linux系统入门命令大全,Linux常用命令5 - Linux 入门常用命令_Linux教程_Linux公社-Linux系统门户网站...
- 微服务分布式企业框架 Springmvc+mybatis+shiro+Dubbo+ZooKeeper
- socket:通常每个套接字地址(协议/网络地址/端口)只允许使用一次
- HashSet vs TreeSet vs LinkedHashSet
- 最优二叉搜索树(动态规划)
- Git 学习笔记--git 查看某个文件的修改历史