問題: https://code.google.com/codejam/contest/1460488/dashboard#s=p0
なんかアルファベット変換されてるらしいのでサンプルからわかる文字変換のマッピングを使って,与えられる文字列を変換したものを求める.
最初はテキトーに手でやってたら z とかがなかったのでアレ?と思ってコード書いて無いもの2つあったからテキトーに入れ替えて提出したらAC.
package main import ( "bufio" "fmt" "io" "io/ioutil" "os" "strconv" ) func run() { m := map[rune]rune{ 'c':'e','g':'v', 'k':'i','o':'k','s':'n','w':'f','d':'s','h':'x','l':'g','p':'r','t':'w', 'x':'m','a':'y', 'e':'o', 'i':'d','m':'l','q':'z', 'u':'j', 'y':'a','b':'h', 'f':'c', ' ':' ','j':'u','n':'b', 'r':'t', 'v':'p','z':'q', } for t, T := 1, s.next(); t <= T; t++ { line := s.nextLine() s.print("Case #", t, ": ") for _, c := range line { s.print(string(m[c])) } s.print("\n") } } func preExecute() { m := make(map[rune]byte) for t, T := 1, s.next(); t <= T; t++ { line := s.nextLine() line2 := s.nextLine() for i, c := range line { m[c] = line2[i] } } m['q'] = 'z' m['z'] = 'q' for k, v := range m { fmt.Println("'" + string(k) + "':'" + string(v) + "',") } } func main() { s = NewInOut(os.Stdin, os.Stdout) run() s.Flush() } var ( s *InOut ) // io start type InOut struct { in []byte *bufio.Writer } func NewInOut(r io.Reader, w io.Writer) *InOut { in, _ := ioutil.ReadAll(r) return &InOut{in, bufio.NewWriter(w)} } func (s *InOut) next() (r int) { buf := s.in p := 1 for (buf[0] < '0' || '9' < buf[0]) && buf[0] != '-' { buf = buf[1:] } if buf[0] == '-' { p = -1 buf = buf[1:] } for '0' <= buf[0] && buf[0] <= '9' { r = 10*r + int(buf[0]-'0') buf = buf[1:] } r *= p s.in = buf return } func (s *InOut) nextLine() (r string) { buf := s.in for buf[0] == '\n' { buf = buf[1:] } p := 0 for buf[p] != '\n' { p++ } r = string(buf[0:p]) s.in = buf[p:] return } func (s *InOut) nextStr() (r string) { buf := s.in for buf[0] == '\n' || buf[0] == ' ' { buf = buf[1:] } p := 0 for buf[p] != '\n' && buf[p] != ' ' { p++ } r = string(buf[0:p]) s.in = buf[p:] return } func (s *InOut) print(os ...interface{}) { for _, o := range os { switch o.(type) { case byte: s.WriteByte(o.(byte)) case string: s.WriteString(o.(string)) case int: s.WriteString(strconv.Itoa(o.(int))) case int64: s.WriteString(strconv.FormatInt(o.(int64), 10)) default: s.WriteString(fmt.Sprint(o)) } } } func (s *InOut) println(os ...interface{}) { for _, o := range os { s.print(o) } s.print("\n") } func (s *InOut) printlnNow(o interface{}) { fmt.Println(o) } // io end