1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| package main
import "fmt"
fun one() { count := 0 for cock := 0; cock <= 20; cock++ { for hen := 0; hen <= 33; hen++ { for chick := 0; chick <= 100; chick++ { count++ if chick%3 == 0 && cock+hen+chick == 100 && cock*5+hen*3+chick/3 == 100 { fmt.Printf("公鸡:%d, 母鸡:%d, 小鸡:%d\n", cock, hen, chick) } } } } fmt.Println(count) }
func two() { count := 0 for cock := 0; cock <= 20; cock++ { for hen := 0; hen <= 33; hen++ { for chick := 0; chick <= 100; chick += 3 { count++ if cock+hen+chick == 100 && cock*5+hen*3+chick/3 == 100 { fmt.Printf("公鸡:%d, 母鸡:%d, 小鸡:%d\n", cock, hen, chick) } } } } fmt.Println(count) }
func three() { count := 0 for cock := 0; cock <= 20; cock++ { for hen := 0; hen <= 33; hen++ { count++ chick := 100 - cock - hen if chick%3 == 0 && 5*cock+3*hen+chick/3 == 100 { fmt.Printf("公鸡:%d, 母鸡:%d, 小鸡:%d\n", cock, hen, chick) } } } fmt.Println(count) }
func main() { one() two() three() }
|