我也是, 第二题 func main() { var n, m, k int var s string fmt.Scanf("%d %d %d", &;n,&;m,&;k) fmt.Scanf("%s", &;s) data := make([][]int, n) for i,_ := range data { data[i] = make([]int, m) } data[0][0] = 1 count := 1 tempi := 0 tempj := 0 for i:=0; i<k; i++ { fmt.Println(tempi, tempj, data[tempi][tempj], s[i], count) if count == m*n { fmt.Println("Yes") fmt.Println(i) return } if s[i] == 'W' { if tempi > 0 { tempi-- if data[tempi][tempj] == 0 { data[tempi][tempj] = 1 count++ } } } else if s[i] == 'D' { if tempj < m-1 { tempj++ if data[tempi][tempj] == 0 { data[tempi][tempj] = 1 count++ } } } else if s[i] == 'S' { if tempi < n-1 { tempi++ if data[tempi][tempj] == 0 { data[tempi][tempj] = 1 count++ } } } else { if tempj > 0 { tempj-- if data[tempi][tempj] == 0 { data[tempi][tempj] = 1 count++ } } } }
点赞 评论

相关推荐

点赞 评论 收藏
分享
牛客网
牛客企业服务