Skip to content

Instantly share code, notes, and snippets.

@mdaisuke
Created April 25, 2016 22:37
Show Gist options
  • Save mdaisuke/6561416c29e989cbdc5d57d896d7b70c to your computer and use it in GitHub Desktop.
Save mdaisuke/6561416c29e989cbdc5d57d896d7b70c to your computer and use it in GitHub Desktop.
package main
import (
"encoding/csv"
"fmt"
"io"
"log"
"os"
"strconv"
"strings"
)
func main() {
r := csv.NewReader(os.Stdin)
h := make(map[string]int64)
for {
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
log.Fatalf("error: %s", err)
}
title := record[3]
amount, _ := strconv.ParseInt(strings.Join(strings.Split(record[4], ","), ""), 0, 64)
h[title] += amount
}
for k, v := range h {
fmt.Printf("%s:\t%d\n", k, v)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment