Created
August 18, 2014 08:44
-
-
Save yuheiomori/63933dd3dd586095682f to your computer and use it in GitHub Desktop.
RollerCoaster (CodeEval) in go
This file contains hidden or 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
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