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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
func dispatchCoin() int { coins := 50 users := []string{"Matthew", "Sarah", "Augustus", "Heidi", "Emilie", "Peter", "Giana", "Adriano", "Aaron", "Elizabeth"} distribution := make(map[string]int, len(users))
result := 0 for _, v := range users { distribution[v] = 0 for _,n := range v{ if strings.Contains(string(n), "e") || strings.Contains(string(n), "E") { distribution[v] += 1
} else if strings.Contains(string(n), "i") || strings.Contains(string(n), "I") { distribution[v] += 2 } else if strings.Contains(string(n), "o") || strings.Contains(string(n), "O") { distribution[v] += 3 } else if strings.Contains(string(n), "u") || strings.Contains(string(n), "U") { distribution[v] += 4 } }
} for _, v := range distribution { result += v } last := coins - result return last }
func main() { func1 := dispatchCoin() fmt.Println("剩余金币:", func1) }
func dispatchCoin() int { coins := 50 users := []string{"Matthew", "Sarah", "Augustus", "Heidi", "Emilie", "Peter", "Giana", "Adriano", "Aaron", "Elizabeth"} distribution := make(map[string]int, len(users))
result := 0 for _, v := range users { distribution[v] = 0 for _, n := range v { switch n { case 'e', 'E': distribution[v] += 1 case 'i', 'I': distribution[v] += 2 case 'o', 'O': distribution[v] += 3 case 'u', 'U': distribution[v] += 4 } } } for _, v := range distribution { result += v } last := coins - result return last }
func main() { func1 := dispatchCoin() fmt.Println("剩余金币:", func1) }
|