-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplesAndOranges.cpp
More file actions
27 lines (24 loc) · 809 Bytes
/
ApplesAndOranges.cpp
File metadata and controls
27 lines (24 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
Solution to the following problem:
https://www.hackerrank.com/challenges/apple-and-orange/problem
This solution counts the number of apples and oranges that fall
withing the predefined area of the house and prints these numbers.
Simply replace the given function with the one below and run it.
*/
void countApplesAndOranges(int s, int t, int a, int b, vector<int> apples, vector<int> oranges) {
int numApples = 0, numOranges = 0;
for(int i = 0; i < apples.size(); i++)
{
apples[i] += a;
if(apples[i] >= s && apples[i] <= t)
numApples++;
}
for(int i = 0; i < oranges.size(); i++)
{
oranges[i] += b;
if(oranges[i] >= s && oranges[i] <= t)
numOranges++;
}
cout << numApples << endl << numOranges << endl;
return;
}