PAT A1002 A+B for Polynomials(25)
AC代码
转载自https://www.cnblogs.com/zjutJY/p/9413766.html
#include <stdio.h>
#include<string.h>
//输入:两行数据,每行表示一个多项式:第一个数字表示非零项的数目,
//后面每两个数表示一项,分别表示幂次和系数。
//输出:两个多项式的和,格式与输入一样
int main(){
const int MAX_N=1111;
double a=0.0;
int k,n=0,count=0,i;//k:输入的非零项数,n:幂次,a:系数,count:和的非零项数
double p[1111]={0};//声明时使用{0}初始化为全0
//double p[MAX_N];
//memset(p,0,MAX_N);//使用memset方法,注意要加string.h头文件
// for(i=MAX_N-1;i>=0;i--){
// printf("%.1f",p[i]);
// }
//输入第一行数据
scanf("%d",&k);
for(i=0;i<k;i++){
scanf("%d %lf",&n,&a);
p[n]+=a;
}
//输入第二行数据
scanf("%d",&k);
for(i=0;i<k;i++){
scanf("%d %lf",&n,&a);
p[n]+=a;
}
for(i=0;i<MAX_N;i++){
if(p[i]){
count++;
}
}
printf("%d",count);
for(i=MAX_N-1;i>=0;i--){
if(p[i]){
printf(" ");
printf("%d %.1f",i,p[i]);
}
}
return 0;
}
自己写的, 一个都没有通过
#include <cstdio>
#include <algorithm>
#define N 1010
using namespace std;
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
double num[N] = {0.0};
int big = 0, t = 0;
for(int i = 0; i < 2; i++) {
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
int a;
double b;
scanf("%d %1f", &a, &b);
num[a] += b;
//if(big < a) swap(big, a);
//t++;
}
}
for(int i = 0; i < N; i++) {
if(num[i] != 0) {
t++;
}
}
printf("%d", t);
for(int i = N; i >= 0; i--) {
if(num[i] != 0.0){
printf(" %d %.1f", i, num[i]);
}
}
return 0;
}
PAT A1002 A+B for Polynomials(25)的更多相关文章
- PAT 1002. A+B for Polynomials (25) 简单模拟
1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)
1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...
- A1002 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 甲级 1009. Product of Polynomials (25)
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- 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 ...
- PAT Advanced 1009 Product of Polynomials (25 分)(vector删除元素用的是erase)
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- 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: E ...
随机推荐
- Neo4j 简介 2019
Neo4j是一个世界领先的开源图形数据库,由 Java 编写.图形数据库也就意味着它的数据并非保存在表或集合中,而是保存为节点以及节点之间的关系. Neo4j 的数据由下面几部分构成: 节点边属性Ne ...
- python 二分查找代码
二分查找的条件是必须是排好的数字 """二分查找""" def binary_searhc(arr, target): n = len(ar ...
- Linux如何修改环境变量
如果想要环境变量永久生效可以修改下面两个文件中的任何一个: 1 /etc/profile 2 .bash_profile 其中,/etc/profile是全局的环境变量,对所有用户生效,而.bash_ ...
- 树形dp(灯与街道)
https://cn.vjudge.net/contest/260665#problem/E 题意: 给你一个n个点m条边的无向无环图,在尽量少的节点上放灯,使得所有边都被照亮.每盏灯将照亮以它为一个 ...
- 【MyBatis】【SQL】删除最快纪录诞生,从一千万条记录中删除八百万条仅用2分6秒
在 https://www.cnblogs.com/xiandedanteng/p/11669629.html 里我做个一个循环按时间查ID并删除之的程序,运行时间是4分7秒. 但是这个程序走了很多次 ...
- Sublime text3中文版 无法安装插件There are no packages available for installation问题的解决。
说起来差点没被气死,我当时的情况已经是要疯了,连他们的域名都ping不通,我还想着,咋地,要倒闭了? 首选项->插件设置->Package Control->默认 里边的这个配置项 ...
- YOLO: You Only Look Once论文阅读摘要
论文链接: https://arxiv.org/pdf/1506.02640.pdf 代码下载: https://github.com/gliese581gg/YOLO_tensorflow Abst ...
- JS原生代码之倒计时抢购
学到了原声js改变input的disabled的属性值,因为想让倒计时结束的同时,抢购按钮可以被点击.代码为:document.getElementById("buy").disa ...
- solr 初接触
solr教程,值得刚接触搜索开发人员一看 http://blog.csdn.net/awj3584/article/details/16963525
- 九十四:CMS系统之cms后台登录限制
装饰器,验证当前session中是否存在定义的user_id,没有就重定向到登录页 from flask import session, redirect, url_forfrom functools ...