chore: add hackerrank solutions
This commit is contained in:
69
hacker-rank/pangrams/main.go
Normal file
69
hacker-rank/pangrams/main.go
Normal file
@@ -0,0 +1,69 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user