main.go 717 B

123456789101112131415161718192021222324252627282930
  1. // Dup1 prints the text of each line that appears more than
  2. // once in the standard input, preceded by its count.
  3. package main
  4. import "fmt"
  5. func main() {
  6. //这里是 代码包 共享变量的测试
  7. // dup1
  8. //fmt.Printf("dup1:\n")
  9. //Dup1()
  10. //dup2
  11. //fmt.Printf("dup2:\n")
  12. //DUP2()
  13. //fmt.Printf("dup3:\n")
  14. //DUP3()
  15. counts := make(map[string]int)
  16. fatherCounts := make(map[string]map[string]int)
  17. counts["A"] = 1
  18. counts["B"] = 2
  19. fatherCounts["A"] = counts
  20. fmt.Printf("%d\n",counts["A"])
  21. delete(fatherCounts["A"],"A")
  22. fmt.Printf("A:%d,B:%d,C:%d\n", fatherCounts["A"]["A"],fatherCounts["A"]["B"],fatherCounts["A"]["C"]) //默认值会赋0
  23. for key := range fatherCounts {
  24. fmt.Printf("key:%s",key)
  25. }
  26. }