Skip to content

Latest commit

 

History

History
39 lines (37 loc) · 762 Bytes

HJ17坐标移动.md

File metadata and controls

39 lines (37 loc) · 762 Bytes
package main

import (
    "bufio"
    "fmt"
    "os"
    "strings"
    "strconv"
)

func main() {
    var x, y int
    input := bufio.NewScanner(os.Stdin)
    input.Scan()
    commands := strings.Split(input.Text(), ";")
    for _, v := range commands {
        if v == "" || v == " " {
            continue
        }
        if num, err := strconv.Atoi(v[1:]); err != nil {
            continue
        } else {
            command := v[0]
            switch command {
                case 'A':
                    x -= num
                case 'D':
                    x += num
                case 'W':
                    y += num
                case 'S':
                    y -= num
            }
        }
    }
    fmt.Printf("%d,%d", x, y)
}