0

我在使用 Go 时遇到了一些问题,我确实使用了标签tag = true

//  project main.go
package main

import (
    "fmt"
)

func main() {
    var m, odd1, odd2, in1, in2 int
    tag := false
    fmt.Scan(&m)
    for i := 0; i < m; i++ {
        fmt.Scan(&in1, &in2)
        odd1 += in1
        odd2 += in2
        if (in1+in2)&1 == 1 {
            tag = true
        }
    }
    if odd1&1 == 0 && odd2&1 == 0 {
        fmt.Print("0")
        return
    }
    if odd1&1 == 0 && odd2&1 == 1 || odd1&1 == 1 && odd2&1 == 0 {
        fmt.Print("1")
        return
    }
    fmt.Print("-1")
}
4

2 回答 2

4

'Not used' can be understood as 'has no effect'. While you're assigning true to tag, this is not propagated to the outside nor has any effect on the result of the function.

If you'd use tag in a condition or return it, then the compiler wouldn't complain anymore.

于 2013-10-18T18:30:42.977 回答
0

你没有使用标签。你再次分配给它。使用将意味着它位于某物的右侧:if tag { or if tag && odd1 && 1 == testVal {

这是克里斯托弗·普福尔的回答

于 2013-10-18T19:52:59.273 回答