advent-of-code/hacker-rank/pangrams/main.go

70 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-10-26 12:03:06 -06:00
package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
)
/*
* Complete the 'pangrams' function below.
*
* The function is expected to return a STRING.
* The function accepts STRING s as parameter.
*/
func pangrams(s string) string {
// Write your code here
s = strings.ToLower(s)
m := make(map[rune]struct{}, 26)
for _, a := range s {
if a >= 'a' && a <= 'z' {
fmt.Println(a)
m[a] = struct{}{}
}
}
fmt.Println(len(m))
if len(m) == 26 {
return "pangram"
} else {
return "not pangram"
}
}
func main() {
reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)
stdout, err := os.Create(os.Getenv("OUTPUT_PATH"))
checkError(err)
defer stdout.Close()
writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)
s := readLine(reader)
result := pangrams(s)
fmt.Fprintf(writer, "%s\n", result)
writer.Flush()
}
func readLine(reader *bufio.Reader) string {
str, _, err := reader.ReadLine()
if err == io.EOF {
return ""
}
return strings.TrimRight(string(str), "\r\n")
}
func checkError(err error) {
if err != nil {
panic(err)
}
}