-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtask.go
More file actions
40 lines (32 loc) · 598 Bytes
/
task.go
File metadata and controls
40 lines (32 loc) · 598 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
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
const (
isAuto = "auto"
isFreeze = "freeze"
isHeat = "heat"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
temperatures := strings.Fields(scanner.Text())
t1, _ := strconv.Atoi(temperatures[0])
t2, _ := strconv.Atoi(temperatures[1])
scanner.Scan()
action := scanner.Text()
fmt.Println(solution(t1, t2, action))
}
func solution(t1, t2 int, action string) int {
switch {
case action == isAuto,
action == isFreeze && t1 > t2,
action == isHeat && t1 < t2:
return t2
}
return t1
}