Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created August 18, 2014 08:44
Show Gist options
  • Save yuheiomori/63933dd3dd586095682f to your computer and use it in GitHub Desktop.
Save yuheiomori/63933dd3dd586095682f to your computer and use it in GitHub Desktop.
RollerCoaster (CodeEval) in go
package main
import (
"bufio"
"fmt"
"log"
"os"
"unicode"
)
func main() {
file, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
//'scanner.Text()' represents the test case, do something with it
var line string = scanner.Text()
var upper_flg bool = true
for _, r := range line {
if unicode.IsLetter(r) {
if upper_flg {
fmt.Printf("%c", unicode.ToUpper(r))
} else {
fmt.Printf("%c", unicode.ToLower(r))
}
upper_flg = !upper_flg
} else {
fmt.Printf("%c", r)
}
}
fmt.Print("\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment