PAT-甲级-1002
1、来,先看题,https://www.patest.cn/contests/pat-a-practise/1002。
2、需要注意的地方只有一个:两个多项式相加之后,系数可能为零,这些项不应该出现在输出中,也不应该算在总的项数内。
接下来,就是一顿无脑暴力了:
#include<iostream>
#include<iomanip>
using namespace std;
typedef struct {
int expo;
double coef;
} node;
int ka,kb;
node a[],b[];
int exist(node n) {
for(int i=; i<ka; i++) if(a[i].expo==n.expo) return i;
return -;
}
int main(void) {
cin>>ka;
for(int i=; i<ka; i++) cin>>a[i].expo>>a[i].coef;
cin>>kb;
for(int i=; i<kb; i++) cin>>b[i].expo>>b[i].coef;
int len=ka;
for(int i=; i<kb; i++) {
if(exist(b[i])!=-) a[exist(b[i])].coef+=b[i].coef;
else {
a[len].expo=b[i].expo;
a[len++].coef+=b[i].coef;
}
}
for(int i=; i<len; i++) {
for(int j=i+; j<len; j++) {
if(a[j].expo>a[i].expo) {
double c=a[i].coef;
int e=a[i].expo;
a[i].coef=a[j].coef;
a[i].expo=a[j].expo;
a[j].coef=c;
a[j].expo=e;
}
}
}
int count=;
for(int i=; i<len; i++) {
if(a[i].coef) count++;
}
cout<<count;
for(int i=; i<len; i++)
if(a[i].coef!=)
printf(" %d %.1lf",a[i].expo,a[i].coef);
cout<<endl;
}
其实,只要做好“零系数”这个特殊情况的处理,就不会报错了。
PAT-甲级-1002的更多相关文章
- 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
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- 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
https://pintia.cn/problem-sets/994805342720868352/problems/994805526272000000 This time, you are sup ...
- PAT甲级1002水题飘过
#include<iostream> #include<string.h> using namespace std; ]; int main(){ int n1, n2; wh ...
- PAT甲级——1002 A+B for Polynomials
PATA1002 A+B for Polynomials This time, you are supposed to find A+B where A and B are two polynomia ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级1107. Social Clusters
PAT甲级1107. Social Clusters 题意: 当在社交网络上注册时,您总是被要求指定您的爱好,以便找到一些具有相同兴趣的潜在朋友.一个"社会群体"是一群拥有一些共同 ...
- PAT甲级代码仓库
大道至简,知易行难.希望能够坚持刷题. PAT甲级真题题库,附上我的代码. Label Title Score Code Level 1001 A+B Format 20 1001 * 1002 A+ ...
随机推荐
- PHP获取文件的绝对路径
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ===========PH ...
- Android 8.0 功能和 API
Android 8.0 为用户和开发者引入多种新功能.本文重点介绍面向开发者的新功能. 用户体验 通知 在 Android 8.0 中,我们已重新设计通知,以便为管理通知行为和设置提供更轻松和更统一的 ...
- 在web中使用HTTPS
背景 目前网上流行的是HTTP协议,HTTPS协议还在逐步推广的过程中. HTTP协议以明文发送内容,容易被攻击者窃听.HTTPS在HTTP的基础上加入了SSL协议,SSL依靠证书来验证服务器的身份[ ...
- java 多态(动态绑定)
一.面向对象最核心的机制--动态绑定,也叫多态 1.1.通过下面的例子理解动态绑定,即多态 1 package javastudy.summary; 2 3 class Animal { 4 /** ...
- 使用vs编译事件来动态发布配置文件
我们知道开发有很多的环境,一般我们会分为开发环境,测试环境,生产环境.而我们使用的vs默认配置就两种:Debug和Release.当然vs支持通过配置管理器来添加,编辑及删除配置. 为此不同的环境和配 ...
- Run Away 模拟退火
Run Away Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- VBA /VB/VB中合成分散数据方法
公司用于项目号的合成,怕忘记,特此放上这里.若能帮助其它道友,善莫大焉. 比如:001,004,006,007,008,009,010 结果可以输出:001,004,006-010 逻辑:1.获得数据 ...
- Python3常用学习网站总结(随时更新)
Python资源大全 http://python.jobbole.com/84464/ https://github.com/jobbole/awesome-python-cn scrapy: h ...
- 【vue系列之二】详解vue-cli 2.0配置文件
上次给大家分享的是用vue-cli快速搭建vue项目,虽然很省时间和精力,但想要真正搞明白,我们还需要对其原理一探究竟. 大家拿到一个项目,要快速上手,正确的思路是这样的: 首先,如果在项目有read ...
- wxPython中菜单、按钮学习
---恢复内容开始--- wx.Window 是一个基类,许多构件从它继承.包括 wx.Frame 构件.技术上这意味着,我们可以在所有的 子类中使用 wx.Window 的方法.我们这里介绍它的几种 ...