Last active
June 18, 2017 07:27
-
-
Save ifukazoo/5d69aaa57235da37f1860d5adc898cd1 to your computer and use it in GitHub Desktop.
プログラミング出題サイト用
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" | |
"os" | |
"strconv" | |
"strings" | |
) | |
func main() { | |
scanner := NewEScanner() | |
ints := eAtois(strings.Split(scanner.GetLine(), " ")) | |
for _, v := range ints { | |
fmt.Println(v) | |
} | |
} | |
func eAtois(words []string) []int { | |
integers := make([]int, len(words)) | |
for i := range integers { | |
integers[i] = eAtoi(words[i]) | |
} | |
return integers | |
} | |
func eAtoi(s string) int { | |
var ( | |
n int | |
err error | |
) | |
if n, err = strconv.Atoi(s); err != nil { | |
os.Exit(1) | |
} | |
return n | |
} | |
// EScanner bufio.Scanner の操作からエラー処理を除去 | |
type EScanner bufio.Scanner | |
// NewEScanner EScanner作成 | |
func NewEScanner() *EScanner { | |
return (*EScanner)(bufio.NewScanner(os.Stdin)) | |
} | |
// GetLine 1行取得 | |
func (p *EScanner) GetLine() string { | |
(*bufio.Scanner)(p).Scan() | |
if err := (*bufio.Scanner)(p).Err(); err != nil { | |
os.Exit(1) | |
} | |
return (*bufio.Scanner)(p).Text() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment