print the number of apples and oranges that land on Sam's house, each on a separate line. Full Question read on here.
Solution in C# -
class Solution {
static void countApplesAndOranges(int s, int t, int a, int b, int[] apples, int[] oranges) {
int app = 0;
int ora = 0;
for(int i=0; i<apples.Length; i++)
{
int dist = a + apples[i];
if(dist >= s && dist <= t)
app++;
}
foreach(int o in oranges)
{
int dist = b + o;
if(dist >= s && dist <= t)
ora++;
}
Console.WriteLine(app);
Console.WriteLine(ora);
}
static void Main(string[] args) {
string[] st = Console.ReadLine().Split(' ');
int s = Convert.ToInt32(st[0]);
int t = Convert.ToInt32(st[1]);
string[] ab = Console.ReadLine().Split(' ');
int a = Convert.ToInt32(ab[0]);
int b = Convert.ToInt32(ab[1]);
string[] mn = Console.ReadLine().Split(' ');
int m = Convert.ToInt32(mn[0]);
int n = Convert.ToInt32(mn[1]);
int[] apples = Array.ConvertAll(Console.ReadLine().Split(' '), applesTemp => Convert.ToInt32(applesTemp));
int[] oranges = Array.ConvertAll(Console.ReadLine().Split(' '), orangesTemp => Convert.ToInt32(orangesTemp));
countApplesAndOranges(s, t, a, b, apples, oranges);
}
}
Post a Comment