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 ...
随机推荐
- 2019.9.5 Balanced Lineup
题目传送门 板子*3 #include<iostream> #include<cstdio> #include<cstring> #include<cmath ...
- node和npm版本引起的安装依赖和运行项目失败问题
问题:node版本不同导致的安装依赖版本不同而无法启动 https://www.jianshu.com/p/c07293c8c6d4 实际上问题分为两个部分: 1,npm包管理器安装依赖不成功,此时需 ...
- Elasticsearch删除数据之_delete_by_query
es参考版本:elasticsearch:5.5 _delete_by_query会删除所有query语句匹配上的文档,用法如下: curl -X POST "localhost:9200/ ...
- 内部排序总结之----插入类排序(插入和Shell)
一.直接插入排序 直接插入排序(straight insertion sort)的做法是: 每次从无序表中取出第一个元素,把它插入到有序表的合适位置,使有序表仍然有序. 第一趟比较前两个数,然后把第二 ...
- Flutter打开第三方应用
在flutter中打开第三方应用可以使用url_launcher插件 打开https://pub.dartlang.org/,然后搜索url_launcher,然后点击进入该插件界面 大家在insta ...
- postgresql 字符串转整数 int、integer
--把'1234'转成整数 select cast('1234' as integer ) ; --用substring截取字符串,从第8个字符开始截取2个字符:结果是12 select cast(s ...
- CI框架对HTML输入的处理/CI框架引用ueditor时对提交内容的默认处理
项目里近期用到了富文本编辑器,可是写入数据的时候总是写入, <p xss="removed">内容</p> 所有的样式都会被改写成这样,xss=" ...
- LC 794. Valid Tic-Tac-Toe State
A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to r ...
- UI布局属性大全
第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_centerVertical 垂直居中 android:la ...
- java.lang.reflect.Method.getAnnotation()方法示例【通过反射获取到方法对象再获取方法对象上的注解信息】
转: java.lang.reflect.Method.getAnnotation()方法示例 java.lang.reflect.Method.getAnnotation(Class <T&g ...