-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path11219.go
49 lines (42 loc) · 926 Bytes
/
11219.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
// UVa 11219 - How old are you?
package main
import (
"fmt"
"os"
)
type date struct{ y, m, d int }
func convert(t string) date {
var d date
fmt.Sscanf(t, "%d/%d/%d", &d.d, &d.m, &d.y)
return d
}
func compare(t1, t2 string) int {
current, birth := convert(t1), convert(t2)
age := current.y - birth.y
if current.m < birth.m || current.m == birth.m && current.d < birth.d {
age--
}
return age
}
func main() {
in, _ := os.Open("11219.in")
defer in.Close()
out, _ := os.Create("11219.out")
defer out.Close()
var kase int
fmt.Fscanf(in, "%d", &kase)
var t1, t2 string
for i := 1; i <= kase; i++ {
fmt.Fscanf(in, "\n%s", &t1)
fmt.Fscanf(in, "%s", &t2)
fmt.Fprintf(out, "Case #%d: ", i)
switch years := compare(t1, t2); {
case years < 0:
fmt.Fprintln(out, "Invalid birth date")
case years > 130:
fmt.Fprintln(out, "Check birth date")
default:
fmt.Fprintf(out, "%d\n", years)
}
}
}