1002. A+B for Polynomials (25)

原创 2018年04月17日 17:52:16

注意不能输出系数为0的项

#include<bits/stdc++.h>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,a;
	double b;
	map<int,double> m;
	m.clear();
	vector<int> v;
	//freopen("1002.txt","r",stdin);
	for(int i=0;i<2;i++)
	{
		scanf("%d",&n);
		for(int j=0;j<n;j++)
		{
			scanf("%d %lf",&a,&b);
			//printf("%d %lf\n",a,b);
			if(!m.count(a))
				v.push_back(a);		
			m[a]+=b;		
		}			
	}
	sort(v.begin(),v.end(),cmp);
	int cnt=0;
	for(int i=0;i<v.size();i++)
	{
		if(m[v[i]]!=0.0)
			cnt++;
		//printf(" %d %.1f",v[i],m[v[i]]);
	 } 
	printf("%d",cnt);
	for(int i=0;i<v.size();i++)
	{
		if(m[v[i]]!=0.0)
			printf(" %d %.1f",v[i],m[v[i]]);
	 } 
	return 0;
}

华为路由交换精讲系列25:ISIS技术简介 肖哥视频课程

-
  • 1970年01月01日 08:00

PAT Advanced Level 1002. A+B for Polynomials (25)(Java)

1002. A+B for Polynomials (25) Java代码: import java.util.Iterator; import java.util.Scanner; im...
  • u010388829
  • u010388829
  • 2014-09-13 23:03:23
  • 1175

PAT (Advanced Level) 1002. A+B for Polynomials (25) 解题报告

1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16...
  • qq_21899803
  • qq_21899803
  • 2017-01-24 14:37:40
  • 165

PAT甲级 1002. A+B for Polynomials (25) 题目翻译与答案

1002.多项式A与B的和 这次,假设A和B是两个多项式,求A与B的和多项式。
  • qq278672818
  • qq278672818
  • 2017-01-15 17:50:48
  • 1698

编程题目:PAT(Advanced Level) Practice 1002. A+B for Polynomials (25)

1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16...
  • zhangyalin1992
  • zhangyalin1992
  • 2014-07-13 14:49:39
  • 976

PAT Advanced 1002. A+B for Polynomials (25) (C语言实现)

题目 This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file...
  • Oliver__Lew
  • Oliver__Lew
  • 2017-05-18 23:47:39
  • 335

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

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1002 分析:给出俩个多项式的指数和系数,没有给出基数,只要将指数相同的多项式进行系数相加即可。输出...
  • realxuejin
  • realxuejin
  • 2013-08-23 08:47:32
  • 2064

PAT甲级-1002. A+B for Polynomials (25)多项式

1002. A+B for Polynomials (25)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThis time, y...
  • MIKASA3
  • MIKASA3
  • 2018-02-17 22:21:14
  • 50

1002. A+B for Polynomials

#include#includefloat a[1001];// 数组要设置为全局变量 否则会出错int main(){ float q; int m,n,t; memset(a,0,sizeof(i...
  • zjjee
  • zjjee
  • 2014-01-31 23:17:16
  • 1192

PAT A1002 A+B for Polynomials (25)

题目地址:https://www.patest.cn/contests/pat-a-practise/1002题目描述:This time, you are supposed to find A+B ...
  • xsj_blog
  • xsj_blog
  • 2016-07-25 10:54:50
  • 218
收藏助手
不良信息举报
您举报文章:1002. A+B for Polynomials (25)
举报原因:
原因补充:

(最多只允许输入30个字)