Skip to content

Commit 66b9a58

Browse files
authored
12_apple-and-orange
1 parent 6329145 commit 66b9a58

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

algorithms/12_apple-and-orange.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
#
10+
# Complete the 'countApplesAndOranges' function below.
11+
#
12+
# The function accepts following parameters:
13+
# 1. INTEGER s
14+
# 2. INTEGER t
15+
# 3. INTEGER a
16+
# 4. INTEGER b
17+
# 5. INTEGER_ARRAY apples
18+
# 6. INTEGER_ARRAY oranges
19+
#
20+
21+
def countApplesAndOranges(s, t, a, b, apples, oranges):
22+
# Write your code here
23+
app = 0
24+
ora = 0
25+
for i in range(len(apples)):
26+
te = a+ apples[i]
27+
if(te in range(s,t+1)):
28+
app+=1
29+
for i in range(len(oranges)):
30+
te = b+ oranges[i]
31+
if(te in range(s,t+1)):
32+
ora+=1
33+
# for x in apples:
34+
# na = a+(x)
35+
# if na >= s and na <= t:
36+
# app=app+1
37+
# for x in oranges:
38+
# na = b+(x)
39+
# if na >=s and na <=t:
40+
# ora=ora+1
41+
print(app)
42+
print(ora)
43+
44+
if __name__ == '__main__':
45+
first_multiple_input = input().rstrip().split()
46+
47+
s = int(first_multiple_input[0])
48+
49+
t = int(first_multiple_input[1])
50+
51+
second_multiple_input = input().rstrip().split()
52+
53+
a = int(second_multiple_input[0])
54+
55+
b = int(second_multiple_input[1])
56+
57+
third_multiple_input = input().rstrip().split()
58+
59+
m = int(third_multiple_input[0])
60+
61+
n = int(third_multiple_input[1])
62+
63+
apples = list(map(int, input().rstrip().split()))
64+
65+
oranges = list(map(int, input().rstrip().split()))
66+
67+
countApplesAndOranges(s, t, a, b, apples, oranges)

0 commit comments

Comments
 (0)