[highly opinionated] Template for Go on CodeForces.com

Правка en1, от eval_apply, 2021-11-16 00:50:43

What?

A quick and efficient template for writing code on CodeForces.com using Go. Mostly consists of input/output improvers and helpers.

Why?

Because I've needed my code to be more compact, wanted more clarity and ease of usage. And to speed-up a bit too.

How you've made it?

I've got rid of the rather slow group of simple scanners from "fmt", namely:

  • fmt.Scan
  • fmt.Scanln
  • fmt.Scanf

because of their clumsiness and their slowness compared to other available options in Go. To learn more, start with checking some benchmarks from this post.

Instead, there is a reader from bufio, which reads from os.Stdin and is much faster. And it simplifies the code of the program too, because instead of:

var variable type
fmt.Scan(variable)

You can now write like:

variable := readType()

To read an Array (or Slice, actually) with items of some type, located on the current line and separated by spaces, just append 's' at the end of the desired read function like so:

arrayOfVars := readTypes()

Template

Suggestions?

Leave them in the comments below, I'll update the template, if necessary.

Happy solving! :)

Теги template, go template, go, golang

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en7 Английский eval_apply 2023-01-09 14:40:01 22 Tiny change: 'n Author: Yakov, frvr.ru\n*/\n\npa' -> 'n Author: algo.tensai.me\n*/\n\npa'
en6 Английский eval_apply 2021-11-16 01:03:48 0 (published)
en5 Английский eval_apply 2021-11-16 01:03:22 6
en4 Английский eval_apply 2021-11-16 01:02:50 82
en3 Английский eval_apply 2021-11-16 01:00:34 61
en2 Английский eval_apply 2021-11-16 00:58:22 4482
en1 Английский eval_apply 2021-11-16 00:50:43 1396 Initial revision (saved to drafts)