-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
113 lines (89 loc) · 2.44 KB
/
main.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
"strings"
)
/*
* 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
*/
func countApplesAndOranges(s int32, t int32, a int32, b int32, apples []int32, oranges []int32) {
// Write your code here
var appleCount, orangeCount int32
for _, apple := range apples {
if apple+a >= s && apple+a <= t {
appleCount++
}
}
for _, orange := range oranges {
if orange+b >= s && orange+b <= t {
orangeCount++
}
}
fmt.Println(appleCount)
fmt.Println(orangeCount)
}
func main() {
reader := bufio.NewReaderSize(os.Stdin, 16*1024*1024)
firstMultipleInput := strings.Split(strings.TrimSpace(readLine(reader)), " ")
sTemp, err := strconv.ParseInt(firstMultipleInput[0], 10, 64)
checkError(err)
s := int32(sTemp)
tTemp, err := strconv.ParseInt(firstMultipleInput[1], 10, 64)
checkError(err)
t := int32(tTemp)
secondMultipleInput := strings.Split(strings.TrimSpace(readLine(reader)), " ")
aTemp, err := strconv.ParseInt(secondMultipleInput[0], 10, 64)
checkError(err)
a := int32(aTemp)
bTemp, err := strconv.ParseInt(secondMultipleInput[1], 10, 64)
checkError(err)
b := int32(bTemp)
thirdMultipleInput := strings.Split(strings.TrimSpace(readLine(reader)), " ")
mTemp, err := strconv.ParseInt(thirdMultipleInput[0], 10, 64)
checkError(err)
m := int32(mTemp)
nTemp, err := strconv.ParseInt(thirdMultipleInput[1], 10, 64)
checkError(err)
n := int32(nTemp)
applesTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
var apples []int32
for i := 0; i < int(m); i++ {
applesItemTemp, err := strconv.ParseInt(applesTemp[i], 10, 64)
checkError(err)
applesItem := int32(applesItemTemp)
apples = append(apples, applesItem)
}
orangesTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
var oranges []int32
for i := 0; i < int(n); i++ {
orangesItemTemp, err := strconv.ParseInt(orangesTemp[i], 10, 64)
checkError(err)
orangesItem := int32(orangesItemTemp)
oranges = append(oranges, orangesItem)
}
countApplesAndOranges(s, t, a, b, apples, oranges)
}
func readLine(reader *bufio.Reader) string {
str, _, err := reader.ReadLine()
if err == io.EOF {
return ""
}
return strings.TrimRight(string(str), "\r\n")
}
func checkError(err error) {
if err != nil {
panic(err)
}
}