PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25
This time, you are supposed to find A+B where A and B are two polynomials.
Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:
K N1 aN1 N2 aN2 ... NK aNK
where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1,2,⋯,K) are the exponents and coefficients, respectively. It is given that 1≤K≤10,0≤NK<⋯<N2<N1≤1000.
Output Specification:
For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.
Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
Sample Output:
3 2 1.5 1 2.9 0 3.2
解题:
#include<stdio.h>
#include<string.h> int main()
{
int k,i,j,l,c=0;
int temp[1001];
int flag=1;
float arr1[1001],arr2[1001],temparr[1001];
memset(arr1,0,sizeof(arr1));
memset(arr2,0,sizeof(arr2));
memset(temparr,0,sizeof(temparr));
memset(temp,1001,sizeof(temp));
scanf("%d ",&k);
for(i=0;i<k;i++)
{
scanf("%d ",&j);
for(l=0;l<k;l++){
if(temp[l]==j)
{
scanf("%f ",&temparr[j]);
arr1[j]+=temparr[j];
flag=0;
}
}
if(flag==1)
{
temp[i]=j;
scanf("%f ",&arr1[j]);
}
flag=1;
}
//printf("%d %d %.1f",k,j,arr1[1]);
scanf("%d ", &k);
for(i=0;i<k;i++)
{
scanf("%d ",&j);
for(l=0;l<k;l++){
if(temp[l]==j)
{
scanf("%f ",&temparr[j]);
arr2[j]+=temparr[j];
flag=0;
}
}
if(flag==1)
{
temp[i]=j;
scanf("%f ",&arr2[j]);
}
flag=1;
} for(i=0;i<12;i++)
{
arr1[i]=arr1[i]+arr2[i];
}
for(i=0;i<12;i++)
{
if(arr1[i]!=0)
{
c++;
}
}
printf("%d",c);
for(i=12;i>=0;i--)
{
if(arr1[i]!=0)
{
printf(" %d %.1f",i,arr1[i]);
}
}
}
PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25的更多相关文章
- PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...
- PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642
PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) 凌宸1642 题目描述: At the beginning of ever ...
- PAT (Advanced Level) Practice 1006 Sign In and Sign Out (25 分) (排序)
At the beginning of every day, the first person who signs in the computer room will unlock the door, ...
- PAT (Basic Level) Practice 1002 写出这个数 分数 20
读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 10100. 输出格式: 在一行内输出 ...
- PAT (Basic Level) Practice 1005 继续(3n+1)猜想 分数 25
卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对 n=3 进行验证的时 ...
- PAT (Advanced Level) Practice 1001-1005
PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...
- PAT (Advanced Level) Practice(更新中)
Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
随机推荐
- 21条最佳实践,全面保障 GitHub 使用安全
GitHub 是开发人员工作流程中不可或缺的一部分.无论你去哪个企业或开发团队,GitHub 都以某种形式存在.它被超过8300万开发人员,400万个组织和托管超过2亿个存储库使用.GitHub 是世 ...
- Jackson 解析 JSON 详细教程
点赞再看,动力无限. 微信搜「程序猿阿朗 」. 本文 Github.com/niumoo/JavaNotes 和 未读代码博客 已经收录,有很多知识点和系列文章. JSON 对于开发者并不陌生,如今的 ...
- Go语言基础四:数组和指针
GO语言中数组和指针 数组 Go语言提供了数组类型的数据结构. 数组是同一数据类型元素的集合.这里的数据类型可以是整型.字符串等任意原始的数据类型.数组中不允许混合不同类型的元素.(当然,如果是int ...
- 使用传统的方式遍历集合对集合中的数据进行过滤和使用Stream流的方式遍历集合对集合中的数据进行过滤
使用传统的方式,遍历集合,对集合中的数据进行过滤 class Test{ public static void main(String[] args){ ArrayList<String> ...
- YII场景
YII在模型中定义场景后 public function scenarios(){//场景 return [ 'sco1'=>['aid','uphone'], 'sco2'=>['aid ...
- Dapr学习(4)之eShopOnDapr部署(Rancher2.63&k3s)
本篇主要讲述一下github上基于Dapr实现的商城demo在(K8s or K3s)环境中的部署实践,本文环境基于k3s&rancher2.6.3 1.eShopOnDapr源代码及概述 源 ...
- JVM 配置参数 -D,-X,-XX 的区别
转载请注明出处: 最近在安全护网行动,需要针对服务进行不断的安全加固,如 对服务的 log4j 的安全配置进行防护,对 fastjson 的漏洞进行安全加固等,最快的防护方法就是通过在服务启动的时候, ...
- GitHub Pages 站点建设
1.简介 GitHub Pages 是通过 GitHub 托管和发布的公共网页,将纯文本转换为静态博客网站. 您可以使用 GitHub Pages 来展示一些开源项目.博客甚或分享您的简历,有内存限制 ...
- 基础1:JS的原型和原型链究竟
JS的原型和原型链究竟是什么? 1. 从JS创建一个对象开始说起: 1.1 工厂模式创建对象 (缺点是无法知道创建出来的对象是一个什么类型的对象) function createPerson(name ...
- [CF1523C] Compression and Expansion (DP/贪心)
C. Compression and Expansion 题面 一个合法的表单由横向 N N N 行数字链,纵向一层或多层数字链组成,第 k k k 层的数字链(可以想象为前面打了 k k k 个制表 ...