1002. A+B for Polynomials(25)—PAT 甲级
This time,you are supposed to find A+B where A+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 nonezero 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 asthe 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,那么多项式的项数加1;如果累加之后等于0,那么多项式的项数减一。注意:多项式的指数都是整数,不要瞎想了~
#include <iostream>
using namespace std;
double s[1005]={0};
int main() {
int k,n,time=2,count=0;
double ak;
while(time--){
scanf("%d",&k);
while(k--){
scanf(" %d %lf",&n,&ak);
if(s[n]==0)count++;
s[n]+=ak;
if(s[n]==0)count--;
}
}
printf("%d",count);
for(int i=1005;i>=0;i--){
if(s[i]!=0){
printf(" %d %.1lf",i,s[i]);
}
}
printf("\n");
return 0;
}
1002. A+B for Polynomials(25)—PAT 甲级的更多相关文章
- 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 (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) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 【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) 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 分)
题意:给出两个多项式,计算两个多项式的和,并以指数从大到小输出多项式的指数个数,指数和系数. AAAAAccepted code: #include<bits/stdc++.h> usin ...
- 甲级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 fi ...
- 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 ...
随机推荐
- HTTP(S)网络框架的设计
0.麻烦 操作系统提供的网络接口都会令人不爽,要么太接近底层而使用不便,要么层次过高又不提供底层点的接口供设置参数.但是我们不能期望系统API做得很高级,因为没有绝对合适的网络库,必须定制化从而达到适 ...
- AndroidStudio项目打包成jar
AndroidStudio项目打包成jar 前言:在eclipse中我们知道如何将一个项目导出为jar包,现在普遍AndroidStuido开发,这里一步一步详加介绍AS项目打包成jar,jar和ar ...
- 已经不再使用的表为什么数据页还在SQLServer的内存缓存中
1. 问题发现 在学习内存调优时,使用如下代码,查询目前内存缓冲区中生产数据库的每个对象缓存页计数 SELECT count(*)AS cached_pages_count ,name ,index_ ...
- golang 获取变量类型的字符串格式 列举变量类型
fmt.Println(reflect.TypeOf(var)) switch xxx.(type){ case int:.... case float32:... case float64:... ...
- 沉淀再出发:dubbo的基本原理和应用实例
沉淀再出发:dubbo的基本原理和应用实例 一.前言 阿里开发的dubbo作为服务治理的工具,在分布式开发中有着重要的意义,这里我们主要专注于dubbo的架构,基本原理以及在Windows下面开发出来 ...
- [EffectiveC++]item24:若所有参数皆需类型转换,请为此采用non-member函数
Declare non-member functions when type conversions should apply to all parameters. 104页 只有当参数被列于参数列( ...
- [EffectiveC++]item23:Prefer non-member non-friend functions to member functions
99页 导致较大封装性的是non-member non-friend函数,因为它并不增加“能否访问class内之private成分”的函数数量.
- codeforces 703E Mishka and Divisors
codeforces 703E Mishka and Divisors 题面 给出大小为\(1000\)的数组和一个数\(k\),求长度最短的一个子序列使得子序列的元素之积是\(k\)的倍数,如果有多 ...
- yarn logs -applicationId [applicationID]
yarn logs -applicationId application_1435648583743_0001 报错: tmp/logs/.../application_1435648583743_0 ...
- ajax获取json形式得题目和答案 实现答题功能
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...