Created
April 13, 2019 19:43
-
-
Save marti1125/9ba6895e0e3cc0eb805249e999d8a005 to your computer and use it in GitHub Desktop.
centuryFromYear
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func centuryFromYear(year int) int { | |
r := 1 | |
s := strconv.Itoa(year) | |
if len(s) == 4 { | |
a := string(s[0:2]) | |
b := string(s[2:4]) | |
c, _ := strconv.Atoi(a) | |
d, _ := strconv.Atoi(b) | |
if d > 0 { | |
c = c + 1 | |
} | |
r = c | |
} | |
if len(s) == 3 { | |
a := string(s[0:1]) | |
b := string(s[1:3]) | |
c, _ := strconv.Atoi(a) | |
d, _ := strconv.Atoi(b) | |
if d > 0 { | |
c = c + 1 | |
} | |
r = c | |
} | |
return r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment