remove: project domain visits2.b

This commit is contained in:
Inanc Gumus
2019-04-23 00:31:25 +03:00
parent bb75efbaf8
commit 9973f1c280
2 changed files with 0 additions and 90 deletions

View File

@@ -1,8 +0,0 @@
learngoprogramming.com turkey 10
learngoprogramming.com turkey 5
learngoprogramming.com usa 10
learngoprogramming.com usa 20fds
golang.org germany 4
golang.org germany 6
golang.org italy 5
golang.org italy 10

View File

@@ -1,82 +0,0 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
type visit struct {
domain string
country string
}
var (
// use a comparable struct for the keys
visits = make(map[visit]int)
domains, countries []string
dupDomains = make(map[string]bool)
dupCountries = make(map[string]bool)
line int
)
in := bufio.NewScanner(os.Stdin)
for in.Scan() {
line++
fields := strings.Fields(in.Text())
if len(fields) != 3 {
fmt.Printf("Wrong input: %v\n", fields)
return
}
v := visit{
domain: fields[0],
country: fields[1],
}
// increase the visit counts per domain + country
fhits := fields[2]
hits, err := strconv.Atoi(fhits)
if err != nil {
fmt.Printf("Wrong input: %q (line #%d)\n", fhits, line)
return
}
visits[v] += hits
// only add the domain once
if !dupDomains[v.domain] {
domains = append(domains, v.domain)
dupDomains[v.domain] = true
}
// only add the country once
if !dupCountries[v.country] {
countries = append(countries, v.country)
dupCountries[v.country] = true
}
}
// print the summary grouped by domain
for _, d := range domains {
fmt.Println(d)
for _, c := range countries {
v := visit{domain: d, country: c}
fmt.Printf("\t%s %d\n", c, visits[v])
}
}
}