首页 > 代码库 > PAT Basic Level 1012
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。