*1012. 数字分类

 1 /*
 2  * Main.c
 3  * 1012. 数字分类
 4  *  Created on: 2014年8月30日
 5  *      Author: Boomkeeper
 6  ********部分通过******
 7  */
 8 
 9 #include <stdio.h>
10 #include <math.h>
11 
12 void A1(int in,int* sum){
13 
14     if(in%5==0&&in%2==0)
15         (*sum)+=in;
16 }
17 
18 void A2(int in,int* sum,int* count){
19 
20     if(in%5==1){
21         (*sum)+=pow(-1,*count)*in;
22         (*count)++;
23     }
24 }
25 
26 void A3(int in,int* count){
27 
28     if(in%5==2)
29         (*count)++;
30 }
31 
32 void A4(int in,int* sum,int* count){
33 
34     if(in%5==3){
35         (*count)++;
36         (*sum)+=in;
37     }
38 }
39 
40 void A5(int in,int* max){
41 
42     if(in%5==4)
43         if(*max<in)
44             *max=in;
45 }
46 
47 void output(int* sum1,int* sum2,int* count3,int* sum4,int* count4,int* max){
48     if(*sum1==0)
49         printf("N ");
50     else
51         printf("%d ",*sum1);
52 
53     /*交错求和结果可能为0,输出N还是0有待判断*/
54     if(*sum2==0)
55         printf("N ");
56     else
57         printf("%d ",*sum2);
58 
59     if(*count3==0)
60         printf("N ");
61     else
62         printf("%d ",*count3);
63 
64     if(*count4==0)
65         printf("N ");
66     else
67         printf("%.1f ",(float)(*sum4)/(*count4));
68 
69     if(*max==0)
70         printf("N");
71     else
72         printf("%d
",*max);
73 }
74 
75 int main(void){
76 
77     int in;
78     int n;//题目中的n
79     int i;
80     int sum1=0,sum2=0,sum4=0;//A1、A2、A4中的sum
81     int count2=0,count3=0,count4=0;//A2、A3、A4中统计个数
82     int max=0;//A5中记录最大数
83 
84     scanf("%d",&n);
85 
86     for(i=0;i<n;i++){
87         scanf("%d",&in);
88         A1(in,&sum1);
89         A2(in,&sum2,&count2);
90         A3(in,&count3);
91         A4(in,&sum4,&count4);
92         A5(in,&max);
93     }
94 
95     output(&sum1,&sum2,&count3,&sum4,&count4,&max);
96 
97     return 0;
98 }

这个题目有点时间长了,当时做完没提交,一下子想不起来当时的思路,先发布出来吧,不然回头又忘了。

题目链接:

http://pat.zju.edu.cn/contests/pat-b-practise/1012

.

原文地址:https://www.cnblogs.com/boomkeeper/p/1012b.html