当前位置: 代码迷 >> 综合 >> PTA 数字分类 (20分)
  详细解决方案

PTA 数字分类 (20分)

热度:76   发布时间:2024-02-26 11:50:29.0

每个人都有崩溃的时候,就看你的抗压能力到底有多强,如果你的抗压能力强,有办法可以支撑到你能面对并且解决这些困难的话,你就没有问题。                                                                          ----喻言

给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字:

  • A?1?? = 能被 5 整除的数字中所有偶数的和;
  • A?2?? = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 n?1???n?2??+n?3???n?4???;
  • A?3?? = 被 5 除后余 2 的数字的个数;
  • A?4?? = 被 5 除后余 3 的数字的平均数,精确到小数点后 1 位;
  • A?5?? = 被 5 除后余 4 的数字中最大数字。

输入格式:

每个输入包含 1 个测试用例。每个测试用例先给出一个不超过 1000 的正整数 N,随后给出 N 个不超过 1000 的待分类的正整数。数字间以空格分隔。

输出格式:

对给定的 N 个正整数,按题目要求计算 A?1??~A?5?? 并在一行中顺序输出。数字间以空格分隔,但行末不得有多余空格。

若其中某一类数字不存在,则在相应位置输出 N。

输入样例 1:

13 1 2 3 4 5 6 7 8 9 10 20 16 18

输出样例 1:

30 11 2 9.7 9

输入样例 2:

8 1 2 4 5 6 7 9 16

输出样例 2:

N 11 2 N 9
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include <numeric>
#include<unordered_set>
#include <climits>//INT_maxnn
//#include<bits/stdc++.h>
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define INF 0x7fffffff;
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
#define LL unsigned int
#define wc 1e-8
typedef long long ll;
using namespace std;
int x,A[6],N,ct[6];
int main(){cin>>N;for(int i=0;i<N;i++){cin>>x;if(x%5==0){if(x%2==0){ct[1]++;A[1]+=x;}}else if(x%5==1){if(ct[2]%2==0)A[2]+=x;elseA[2]-=x;ct[2]++;}else if(x%5==2){A[3]++;ct[3]++;}else if(x%5==3){A[4]+=x;ct[4]++;}else if(x%5==4){ct[5]++;A[5]=max(A[5],x);}}double jg=A[4]*1.0/ct[4];for(int i=1;i<=5;i++){if(i==5){if(ct[i]==0)printf("N\n");elseprintf("%d\n",A[i]);}else if(i==4){if(ct[i]==0)printf("N ");elseprintf("%.1f ",jg);}else{if(ct[i]==0)printf("N ");elseprintf("%d ",A[i]);}}return 0;
}

 

  相关解决方案