LoginSignup
0
0

More than 1 year has passed since last update.

[A Tour of Go] Exercise: Mapsの自分の解答

Posted at
package main

import (
    "golang.org/x/tour/wc"
)

func WordCount(s string) map[string]int {
    words := make(map[string]int)
    var wordstorage string
    for i:=0; i < len(s); i++ {
        if s[i:i+1] == " " {
            words[wordstorage] += 1
            wordstorage = ""
        } else {
            wordstorage += s[i:i+1]
        }
    }
    words[wordstorage] += 1
    return words
}

func main() {
    wc.Test(WordCount)
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0