add: regex to map as sets example
This commit is contained in:
		| @@ -11,6 +11,8 @@ import ( | |||||||
| 	"bufio" | 	"bufio" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"regexp" | ||||||
|  | 	"strings" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func main() { | func main() { | ||||||
| @@ -24,10 +26,20 @@ func main() { | |||||||
| 	in := bufio.NewScanner(os.Stdin) | 	in := bufio.NewScanner(os.Stdin) | ||||||
| 	in.Split(bufio.ScanWords) | 	in.Split(bufio.ScanWords) | ||||||
|  |  | ||||||
|  | 	rx := regexp.MustCompile(`[^a-z]+`) | ||||||
|  |  | ||||||
| 	words := make(map[string]bool) | 	words := make(map[string]bool) | ||||||
| 	for in.Scan() { | 	for in.Scan() { | ||||||
| 		words[in.Text()] = true | 		word := strings.ToLower(in.Text()) | ||||||
|  | 		word = rx.ReplaceAllString(word, "") | ||||||
|  | 		if len(word) > 2 { | ||||||
|  | 			words[word] = true | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// for word := range words { | ||||||
|  | 	// 	fmt.Println(word) | ||||||
|  | 	// } | ||||||
|  |  | ||||||
| 	if words[query] { | 	if words[query] { | ||||||
| 		fmt.Printf("The input contains %q.\n", query) | 		fmt.Printf("The input contains %q.\n", query) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user