PAT Basic Level 1012

Posted Ponytai1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT Basic Level 1012相关的知识,希望对你有一定的参考价值。

  1 #include <stdio.h>
  2 int main ()
  3 {
  4     int ret1;
  5     int ret2;
  6     int ret3;
  7     double ret4;
  8     int ret5;
  9     int array[1000] = {0};
 10     int size;
 11     int p = 0 ;
 12     scanf("%d",&size);
 13     int i = size;
 14     while(i > 0)
 15     {
 16         scanf("%d",&array[p]);
 17         p++;
 18         i--;
 19     }
 20     int temp = 0; 
 21     int flag01 = 0;
 22     for(i = 0;i < size;i++)          //A1
 23     {
 24         if(array[i]%5 == 0&&array[i] % 2 == 0)
 25         {
 26             temp += array[i];
 27             flag01 = 1;
 28         } 
 29     } 
 30     if(flag01 == 1)
 31     {
 32         ret1 = temp;
 33      }                       
 34     
 35     /*int max = array[0];
 36     for(i = 0;i < size;i++)
 37     {
 38         if(array[i] > max)
 39         {
 40             max = array[i];
 41          } 
 42     } 
 43     */
 44     int flag = 1;                
 45     int sum = 0;
 46     int flag02 = 0; 
 47     for(i = 0;i < size;i++)          //A2
 48     {
 49         if(array[i] % 5 == 1)
 50         {
 51             sum += flag*array[i];
 52             flag = -flag;
 53             flag02 = 1;
 54         }
 55     }
 56     if (flag02 == 1)
 57     {
 58         ret2 = sum;
 59     }
 60     
 61     
 62     int cnt = 0;
 63     int flag03 = 0;
 64     for(i = 0;i < size;i++)    //A3
 65     {
 66         if(array[i] % 5 == 2)
 67         {
 68             cnt++;
 69             flag03 = 1;
 70         }
 71     }
 72     if(flag03 == 1)
 73     {
 74         ret3 = cnt;
 75     }
 76     
 77     double sum2 = 0;
 78     double cnt2 = 0;
 79     int flag04 = 0;
 80     for(i = 0;i < size;i++)       //A4
 81     {
 82         if(array[i] % 5 == 3)
 83         {
 84             cnt2++;
 85             sum2 += array[i];
 86             flag04 = 1;
 87         } 
 88     }
 89     if(flag04 == 1)
 90     {
 91         ret4 = sum2/cnt2;
 92      } 
 93     
 94     
 95     int max = 0;
 96     int flag2 = 0; //判断有无余4的数字 
 97     for(i = 0;i < size;i++)          //A5
 98     {
 99         if(array[i] % 5 == 4)
100         {
101             if(flag2 == 0)
102             {
103                 max = array[i];
104                 flag2 = 1;
105             }
106             if(array[i] > max)
107             {
108                 max = array[i];
109             }
110          } 
111     }
112     if(flag2 != 0 )
113     {
114         ret5 = max;
115      } 
116      if(flag01 == 1)
117      printf("%d ",ret1);
118      else
119      printf("N ");
120      if(flag02 == 1)
121      printf("%d ",ret2);
122      else
123      printf("N ");
124      if(flag03 == 1)
125      printf("%d ",ret3);
126      else
127      printf("N ");
128      if(flag04 == 1)
129      printf("%.1lf ",ret4);
130      else
131      printf("N ");
132      if(flag2 == 1)
133      printf("%d",ret5);
134      else
135      printf("N");
136     
137     
138     return 0;
139  } 

 

以上是关于PAT Basic Level 1012的主要内容,如果未能解决你的问题,请参考以下文章

PAT (Basic Level) Practice (中文) 1012 数字分类

PAT (Basic Level) Practise 1040 有几个PAT(DP)

PAT Basic Level 1033

PAT Basic Level 1009

PAT Basic Level 1002

PAT Basic Level 1036