Last active
August 17, 2017 20:59
-
-
Save Horaddrim/cdca0a72d5b049640f46817d5992a7f1 to your computer and use it in GitHub Desktop.
A simple implementation for a future project >:D
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 ( | |
"fmt" | |
"os" | |
"strings" | |
) | |
func colherEstatisticas(palavras []string) map[string]int { | |
estatisticas := make(map[string]int) | |
for _,palavra := range palavras { | |
inicial := strings.ToUpper(string(palavra)) | |
contador, encontrado := estatisticas[inicial] | |
if encontrado { | |
estatisticas[inicial] = contador + 1 | |
} else { | |
estatisticas[inicial] = 1 | |
} | |
} | |
return estatisticas | |
} | |
func imprimir(estatisticas map[string]int) { | |
fmt.Println("Contagem das palavras iniciadas com cada letra: ") | |
for inicial,contador := range estatisticas { | |
fmt.Printf("%s = %d\n", inicial, contador) | |
} | |
} | |
func main(){ | |
palavras := os.Args[1:] | |
estatisticas := colherEstatisticas(palavras) | |
imprimir(estatisticas) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment