首页 > 其他分享 >PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25

PAT (Advanced Level) Practice 1002 A+B for Polynomials 分数 25

时间:2022-09-22 15:26:24浏览次数:42  
标签:temparr 25 PAT temp Level scanf flag arr2 arr1

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
  代码长度限制 16 KB 时间限制 400 ms 内存限制 64 MB   解题:

#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]);
}
}
}

 

标签:temparr,25,PAT,temp,Level,scanf,flag,arr2,arr1
From: https://www.cnblogs.com/slowlydance2me/p/slowlydance2me_1002A.html

相关文章

  • PAT (Basic Level) Practice 1029 旧键盘 分数 20
    旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。输入格式:输入在2......
  • PAT (Basic Level) Practice 1030 完美数列 分数 25
    给定一个正整数数列,和正整数 p,设这个数列中的最大值是 M,最小值是 m,如果 M≤mp,则称这个数列是完美数列。现在给定参数 p 和一些正整数,请你从中选择尽可能多的数构......
  • PAT (Basic Level) Practice 1031 查验身份证 分数 15
    一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的......
  • PAT (Basic Level) Practice 1032 挖掘机技术哪家强 分数 20
    为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。输入格式:输入在第1行给出不超过 105 的正整数......
  • PAT (Basic Level) Practice 1033 旧键盘打字 分数 20
    旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?输入格式:输入在2行中分别......
  • PAT (Basic Level) Practice 1021 个位数统计 分数 15
    给定一个 k 位整数 N=dk−1​10k−1+⋯+d1​101+d0​ (0≤di​≤9, i=0,⋯,k−1, dk−1​>0),请编写程序统计每种不同的个位数字出现的次数。例如:给定 N=100311,则......
  • PAT (Basic Level) Practice 1022 D进制的A+B 分数 20
    输入两个非负10进制整数 A 和 B (≤230−1),输出 A+B 的 D (1<D≤10)进制数。输入格式:输入在一行中依次给出3个整数 A、B 和 D。输出格式:输出 A+B ......
  • PAT (Basic Level) Practice 1023 组个最小数 分数 20
    给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们得到......
  • PAT (Basic Level) Practice 1013 数素数 分数 20
    令 Pi​ 表示第 i 个素数。现任给两个正整数 M≤N≤104,请输出 PM​ 到 PN​ 的所有素数。输入格式:输入在一行中给出 M 和 N,其间以空格分隔。输出格式:输......
  • PAT (Basic Level) Practice 1014 福尔摩斯的约会 分数 20
    大侦探福尔摩斯接到一张奇怪的字条:我们约会吧!3485djDkxh4hhGE2984akDfkkkkggEdsbs&hgsfdkd&Hyscvnm 大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的......