• PAT:1012. 数字分类 (20) AC


    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
      int n;
      int A1,A2,A3,A4,A5,tag,numA4,max=-1,A2tag=0;
      A1=A2=A3=A4=A5=tag=numA4=0;
      scanf("%d",&n);
      for(int t=0 ; t<n ; ++t)
      {
        int tmp;
        scanf("%d",&tmp);
        if(tmp%5==0 && tmp%2==0)
          A1+=tmp;
        if(tmp%5==1)
        {
          A2tag=1;
          if(tag==0)        //判断交错加减的标志
          {
            A2+=tmp;
            tag=1;
          }
          else
          {
            A2-=tmp;
            tag=0;
          }
        }
        if(tmp%5==2)
          ++A3;
        if(tmp%5==3)
        {
          A4+=tmp;
          ++numA4;
        }
        if(tmp%5==4 && tmp>max)
          max=tmp;
      }
      //输出
      if(A1==0)
        printf("N ");
      else
        printf("%d ",A1);
    
      if(A2tag==0)        //加减完之后可能会等于0.所以判断不能用A2是否为0,用标记
        printf("N ");
      else
        printf("%d ",A2);
    
      if(A3==0)
        printf("N ");
      else
        printf("%d ",A3);
    
      if(numA4==0)
        printf("N ");
      else
        printf("%.1lf ",(double)A4/numA4);
    
      if(max==-1)
        printf("N
    ");
      else
        printf("%d
    ",max);
    
      //system("pause");
      return 0;
    }
  • 相关阅读:
    #define #undef
    ps
    Find–atime –ctime –mtime的用法与区别总结
    redis
    linux mutex
    private继承
    boost::noncopyable介绍
    Makefile 中:= ?= += =的区别
    linux Tar 命令参数详解
    Ubuntu14.04安装CMake3.0.2
  • 原文地址:https://www.cnblogs.com/Evence/p/4293147.html
Copyright © 2020-2023  润新知