| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package main
- import "fmt"
- func main() {
- // foo1()
- // foo2()
- cities()
- }
- func work(x int) int {
- return x
- }
- func foo1() {
- myMap := make(map[int]int)
- input := [10]int{}
- for i := 0; i < 10; i++ {
- fmt.Scan(&input[i])
- if value, ok := myMap[input[i]]; ok {
- // fmt.Println("Value from cache: ", value)
- fmt.Printf("%d ", value)
- } else {
- myMap[input[i]] = work(input[i])
- // fmt.Println(myMap[input[i]])
- fmt.Printf("%d ", myMap[input[i]])
- }
- }
- }
- func foo2() {
- cache := make(map[int]int, 10)
- for n, i := 0, 0; i < 10; i++ {
- fmt.Scan(&n)
- if _, exists := cache[n]; !exists {
- cache[n] = work(n)
- }
- fmt.Print(cache[n], " ")
- }
- }
- func cities() {
- groupCity := map[int][]string{
- 10: []string{"Ивановка", "Грязь"},
- 100: []string{"Королев", "Электроугли"},
- 1000: []string{"Москва"},
- }
- cityPopulation := map[string]int{
- "Королев": 30,
- "Москва": 200,
- }
- // fmt.Println(groupCity)
- // fmt.Println(cityPopulation)
- for pKey, _ := range cityPopulation {
- //fmt.Println("Searching key", pKey)
- for cKey, _ := range groupCity {
- //fmt.Println(cKey, cValue)
- if cKey != 100 {
- for _, sValue := range groupCity[cKey] {
- //fmt.Println(sValue)
- if sValue == pKey {
- delete(cityPopulation, pKey)
- }
- }
- }
- }
- }
- fmt.Println("...")
- fmt.Println(cityPopulation)
- }
|