Skip to content

Instantly share code, notes, and snippets.

@meysampg
Created April 27, 2019 11:22
Show Gist options
  • Save meysampg/effd052872658872689ad32fc79dc2a6 to your computer and use it in GitHub Desktop.
Save meysampg/effd052872658872689ad32fc79dc2a6 to your computer and use it in GitHub Desktop.
Hackerrank IO template
func main() {
reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
checkError(err)
defer stdout.Close()
writer := bufio.NewWriterSize(stdout, 1024 * 1024)
nk := strings.Split(readLine(reader), " ")
n := nk[0]
kTemp, err := strconv.ParseInt(nk[1], 10, 64)
checkError(err)
k := int32(kTemp)
result := FUNCTION(n, k)
fmt.Fprintf(writer, "%d\n", result)
writer.Flush()
}
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment