pat-B1012-数字分类

题目链接->link

思路

  1. 依照题意列举所有情况即可,注意输出格式,最后一个case输出后面不能带空格。

代码

ps.依旧丑陋…

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>

using namespace std;
const int maxn=1000;
int a[maxn]={0};

int main(){
    int n,i,sum1,sum2,flag,count,max;
    double sum3;
    while(scanf("%d",&n)!=EOF){
        sum1=0;
        sum2=0;
        flag=1;
        count=0;
        sum3=0;
        max=-1;
        int none[5]={0};
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
            if(a[i]%5==0&&a[i]%2==0){//case1
                sum1+=a[i];
                none[0]++;
            }
            else if(a[i]%5==1){//case2
                sum2+=(pow(-1,(flag+1))*a[i]);
                flag++;
                none[1]++;
            }
            else if(a[i]%5==2){//case3
                count++;
                none[2]++;
            }
            else if(a[i]%5==3){//case4
                sum3+=a[i];
                none[3]++;
            }
            else if(a[i]%5==4){//case5
                none[4]++;
                if(a[i]>max)max=a[i];
            }
            else continue;
        }//for1
        for(i=0;i<5;i++){
            if(none[i]==0){
                if(i!=4){
                    printf("N ");
                }
                else printf("N\n");
            }
            else if(i==0){
                printf("%d ",sum1);
            }
            else if(i==1){
                printf("%d ",sum2);
            }
            else if(i==2){
                printf("%d ",count);
            }
            else if(i==3){
                printf("%.1f ",sum3/none[3]);
            }
            else if(i==4){
                printf("%d",max);
            }
        }//for2
    }//while
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值