-
-
Save SerkanSipahi/35d29020b709ecdd72bc620831965b5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"os" | |
"fmt" | |
) | |
func main(){ | |
/** | |
* Description in the book about whats going on: | |
* ======================================================== | |
* This prints the text of each line that appears more than | |
* once in the standard input, preceded by its count | |
* ======================================================== | |
**/ | |
/** | |
* Issue: it does not do whats described (see above). What going wrong? | |
**/ | |
/** | |
* Code: copy past | |
**/ | |
counts := make(map[string]int) | |
input := bufio.NewScanner(os.Stdin) | |
for input.Scan() { | |
counts[input.Text()]++ | |
} | |
for line, n := range counts { | |
fmt.Printf("%d\t%s\n", n, line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment