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 ...
随机推荐
- delphi将两个Strlist合并,求交集 (保留相同的)
Function StrList_Join(StrListA,StrListB:String):String; //将两个Strlist合并,求交集 (保留相同的) var SListA,SListB ...
- layer提示带文字
直接撸代码: //加载层-风格4 layer.msg('加载中', { icon: 16 ,shade: 0.01 });
- Linux系统是否被植入木马的排查流程梳理
在日常繁琐的运维工作中,对linux服务器进行安全检查是一个非常重要的环节.今天,分享一下如何检查linux系统是否遭受了入侵? 一.是否入侵检查 1)检查系统日志 1 2 检查系统错误登陆日志,统计 ...
- 使用pyinstaller 打包python程序
1.打开PyCharm的Terminal,使用命令pip install pyinstaller安装pyinstaller 2.打包命令:pyinstaller --console --onefile ...
- Hibernate3核心API使用
public static void main(String[] args) throws Exception{ // 1. 加载默认的hibernate.cfg.xml的配置文件 Configura ...
- 【转】MAC 配置ssh免密登录
配了挺多次免密登录,老是忘了,备份一下 转载自知乎,如侵删.https://zhuanlan.zhihu.com/p/32279976 -------------------------------- ...
- 基于Scrapy框架的增量式爬虫
概述 概念:监测 核心技术:去重 基于 redis 的一个去重 适合使用增量式的网站: 基于深度爬取的 对爬取过的页面url进行一个记录(记录表) 基于非深度爬取的 记录表:爬取过的数据对应的数据指纹 ...
- Swift3.0项目学习: 创建撰写按钮
import UIKit class PSMainViewController: UITabBarController { override func viewDidLoad() { super.vi ...
- Java泛型(6):extends和super关键字
(1) <T extends A> 因为擦除移除了类型信息,而无界的泛型参数调用的方法只等同于Object.但是我们可以限定这个泛型参数为某个类型A的子集,这样泛型参数声明的引用就可以用类 ...
- 生命周期中mounted和created的区别。
一.什么是生命周期? 用通俗的语言来说,就是Vue中实例或者组件从创建到消灭中间经过的一系列过程.虽然不太严谨,但是也基本上可以理解. 通过一系列实践,现在把所有遇到的问题整理一遍,今天记录一下cre ...