甲级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 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=, , ..., K) are the exponents and coefficients, respectively.
It is given that <= K <= , <= NK < ... < N2 < N1 <=. 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 decimal place. Sample Input
2.4 3.2
1.5 0.5 Sample Output
1.5 2.9 3.2 @:
polynomial 多项式
exponents 指数
coefficients 系数
题目要求:
给出俩个多项式的指数和系数,没有给出基数,只要将指数相同的多项式进行系数相加即可。输出时按照指数从高到低的顺序输出。
注意题意,一开始没有看题意直接看的实例,忽略了负数情况相加之后系数可能为零从而不写,所以常用的单词还是得认得。。。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <math.h> using namespace std; int main()
{
int i,j,a,n;
int con=;
double s[],b;
int vis[];
memset(s,,sizeof(s));
memset(vis,,sizeof(vis)); for(i=;i<;i++)
{
scanf("%d", &n);
for(j=;j<n;j++)
{
scanf("%d %lf",&a,&b);
s[a]+=b;
}
} for(i=;i<=;i++)
if(s[i]!=)
con++; printf("%d", con); for(i=;i>=;i--)
if(s[i]!=)
printf(" %d %.1f",i,s[i]); printf("\n"); return ;
}
甲级1002 A+B for Polynomials (25)的更多相关文章
- 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)
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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 ...
- 【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 (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 polyno ...
- 【PAT甲级】1002 A+B for Polynomials (25 分)
题意:给出两个多项式,计算两个多项式的和,并以指数从大到小输出多项式的指数个数,指数和系数. AAAAAccepted code: #include<bits/stdc++.h> usin ...
随机推荐
- 浅谈Java 8的新特性和使用场景
一.default方法: 通过default方法,可以在接口(Interface interface_name)中添加实例化方法: 代码如下: public interface TestDef ...
- java HtmlEmail发送邮件工具类
package com.sh.xrsite.common.utils; import java.io.File; import java.util.HashMap; import java.util. ...
- ABAP术语-Object Type
Object Type 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/06/1093159.html Description created ...
- mysql数据库关于事务的问题?求解答
表格代码: CREATE TABLE `t_teacher` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) NOT NULL, `deposit` ) DEFA ...
- oracle-sql优化-通过分组和缓存减少不必要的读
环境:aix 7.1,oracle12.1.0.2 cdb 优化前SQL select * from (select row_.*, rownum rownum_ from (select '弱覆盖' ...
- [MIP]mip-script组件自定义 JS 代码使用限制
自mip升级v2版本后,多了一个mip-script组件,很多人就都以为可以写自定义js代码了!然并卵,MIP2页中还是一样不允许自定义javascript代码,所有的交互须通过组件实现. 引用官方说 ...
- php+sqlserver处理读取decimal 类型数据,不满1的数字会去掉0的问题
php+sqlserver处理读取decimal 类型数据,如果数据不满1,会去掉0的问题.比如读取的数据是 0.05,会显示 .05 function convert_number($number) ...
- python面向对象-cs游戏示例
#!/usr/local/bin/python3 # -*- coding:utf-8 -*- class Role(object): n = 123 # 类变量 name = "我是类na ...
- Leecode刷题之旅-C语言/python-58.最后一个单词的长度
/* * @lc app=leetcode.cn id=58 lang=c * * [58] 最后一个单词的长度 * * https://leetcode-cn.com/problems/length ...
- 利用nodejs实现商品管理系统(二)
下面实现商品管理系统 第一步:对应的ejs与数据交换的编写格式. 商品列表界面product.ejs <% for(var i=0;i<list.length;i++){%> < ...