Created
March 22, 2021 14:49
-
-
Save MinSomai/1fbce4e616e7e281647748d4844b2137 to your computer and use it in GitHub Desktop.
Day 28 : Golang | RegEx, Patterns, and Intro to Databases - Hackerrank.go
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" | |
"fmt" | |
"io" | |
"os" | |
"strconv" | |
"strings" | |
"sort" | |
"regexp" | |
) | |
func main() { | |
reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024) | |
NTemp, err := strconv.ParseInt(readLine(reader), 10, 64) | |
checkError(err) | |
N := int32(NTemp) | |
var unsorted []string | |
for NItr := 0; NItr < int(N); NItr++ { | |
firstNameEmailID := strings.Split(readLine(reader), " ") | |
firstName := firstNameEmailID[0] | |
emailID := firstNameEmailID[1] | |
match, _ := regexp.MatchString("[a-z]*@gmail\\.com", emailID) | |
if match { | |
unsorted = append(unsorted, firstName) | |
}else{ | |
continue; | |
} | |
} | |
sort.Strings(unsorted) | |
for _, sorted := range unsorted { | |
fmt.Println(sorted) | |
} | |
} | |
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment