Apple and Orange from Hackerrank.com
https://www.hackerrank.com/challenges/apple-and-orange/problem
[restrict …]
https://www.hackerrank.com/challenges/apple-and-orange/problem
[restrict …]
#include<stdio.h> #include <stdlib.h> void countApplesAndOranges(int s, int t, int a, int b, int apples_count, int* apples, int oranges_count, int* oranges); int main() { int a[]={-2,2,1}; int b[] = {5,-6}; countApplesAndOranges(7,11,5,15,3,a,2,b); return 0; } void countApplesAndOranges(int s, int t, int a, int b, int apples_count, int* apples, int oranges_count, int* oranges) { int i; int m,n; m=n=0; for(i=0;i<apples_count;i++) { if((apples[i] + a) >= s && (apples[i]+a) <= t) { m++; } } for(i=0;i<oranges_count;i++) { if((oranges[i] + b) >= s && (oranges[i]+b) <= t) { n++; } } printf("%d\n%d\n",m,n); }
[/restrict]