-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppleandOrange.js
More file actions
78 lines (57 loc) · 1.82 KB
/
AppleandOrange.js
File metadata and controls
78 lines (57 loc) · 1.82 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'countApplesAndOranges' function below.
*
* The function accepts following parameters:
* 1. INTEGER s
* 2. INTEGER t
* 3. INTEGER a
* 4. INTEGER b
* 5. INTEGER_ARRAY apples
* 6. INTEGER_ARRAY oranges
*/
function countApplesAndOranges(s, t, a, b, apples, oranges) {
// Write your code here
var count=0;
for(var i=0;i<apples.length;i++){
if(s<=(apples[i]+a)&&t>=(apples[i]+a)){
count++;
}
}
console.log(count);
count=0;
for(i=0;i<oranges.length;i++){
if(s<=(oranges[i]+b)&&t>=(oranges[i]+b)){
count++;
}
}
console.log(count);
}
function main() {
const firstMultipleInput = readLine().replace(/\s+$/g, '').split(' ');
const s = parseInt(firstMultipleInput[0], 10);
const t = parseInt(firstMultipleInput[1], 10);
const secondMultipleInput = readLine().replace(/\s+$/g, '').split(' ');
const a = parseInt(secondMultipleInput[0], 10);
const b = parseInt(secondMultipleInput[1], 10);
const thirdMultipleInput = readLine().replace(/\s+$/g, '').split(' ');
const m = parseInt(thirdMultipleInput[0], 10);
const n = parseInt(thirdMultipleInput[1], 10);
const apples = readLine().replace(/\s+$/g, '').split(' ').map(applesTemp => parseInt(applesTemp, 10));
const oranges = readLine().replace(/\s+$/g, '').split(' ').map(orangesTemp => parseInt(orangesTemp, 10));
countApplesAndOranges(s, t, a, b, apples, oranges);
}