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 ...
随机推荐
- 从JMS到KafKa
从JMS到KafKa JMS (1)JMS概念 JMS(Java Message Service,java消息服务)API是一个消息服务的标准或者说是规范,允许应用程序组件基于JavaEE平台创建.发 ...
- 本地访问weblogic控制台无反应,关闭linux操作系统防火墙
有时候,我们在Linux操作系统上成功启动了weblogic,也查看了7001端口的状态是开启的.但是访问weblogic控制台没有反应,也没有报错. 使用 netstat -ano | grep 7 ...
- CTF中PHP反序列化和命令注入的一次简单利用
代码来自第六届防灾科技学院网络安全技能大赛,侵删. 目标 获取Linux服务器根目录下的flag 代码 /*home.php*/ class home{ private $method; privat ...
- Linux设备驱动程序 之 装载和卸载模块
前置说明 本文例子中涉及两个模块hello.ko和world.ko,其中hello导出符号供world使用: insmod 该命令将模块的代码和数据装入内核,然后使用内核的符号表继续模块中任何未解析的 ...
- antd源码分析之——标签页(tabs 3.Tabs的滚动效果)
由于ant Tabs组件结构较复杂,共分三部分叙述,本文为目录中第三部分(高亮) 目录 一.组件结构 antd代码结构 rc-ant代码结构 1.组件树状结构 2.Context使用说明 3.rc-t ...
- ArcGIS Python查看geodatabase(.gdb)版本
代码:10.0不能运行 import arcpy desc = arcpy.Describe(r'C:\Users\dell\Documents\ArcGIS\default.gdb') print ...
- centos6安装sshpass
跳转机需要装这个 #!/bin/bash yum -y install gcc-c++ openssh-clients curl -o sshpass.tar.gz http://sourceforg ...
- [学习]sentinel中的DatatSource(一) ReadableDataSource
sentinel是今年阿里开源的高可用防护的流量管理框架. git地址:https://github.com/alibaba/Sentinel wiki:https://github.com/alib ...
- ELMO及前期工作 and Transformer及相关论文
论文1 https://arxiv.org/pdf/1705.00108.pdf Semi-supervised sequence tagging with bidirectional languag ...
- easyUI之Accordion(分类)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...