Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int a1(const void* a){
- return (*(int*)a % 2 == 0 ? 1 : 0);
- }
- int a2(const void* a){
- if (*(double*)a < 0)
- *(double*)a = *(double*)a * (-1);
- int aa = (int)*(double*)a;
- int flag_1 = 0;
- if (aa % 2 == 0)
- flag_1 = 1;
- else
- return 0;
- int flag_2 = 0;
- if (*(double*)a - aa <= 0.000001)
- flag_2 = 1;
- else return 0;
- if (flag_2 == 1 && flag_1 == 1)
- return 1;
- else return 0;
- }
- int count_if(void* base, size_t num, size_t size, int (*pred)(const void*)){
- int res = 0;
- for (int i = 0; i < num; i++)
- if(pred((char*)base+i*size) == 1)
- ++res;
- return res;
- }
- int main(){
- int count = 20;
- void *arr;
- int size;
- scanf("%d", &size);
- int res = 0;
- switch(size){
- case 4:
- arr = (int*) malloc (count* sizeof(int));
- for (int i = 0; i < count; i++)
- scanf("%d", (int*)arr+i);
- res = count_if(arr, count, sizeof(int), a1);
- break;
- case 8:
- arr = (double*) malloc (count* sizeof(double));
- for (int i = 0; i < count; i++)
- scanf("%lf", (double*)arr+i);
- res = count_if(arr, count, sizeof(double), a2);
- break;
- }
- printf("%d\n", res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement