| 
									
										
										
										
											2019-05-05 18:23:52 +03:00
										 |  |  | // Copyright © 2018 Inanc Gumus | 
					
						
							|  |  |  | // Learn Go Programming Course | 
					
						
							|  |  |  | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/ | 
					
						
							|  |  |  | // | 
					
						
							| 
									
										
										
										
											2019-10-30 19:34:44 +03:00
										 |  |  | // For more tutorials  : https://learngoprogramming.com | 
					
						
							|  |  |  | // In-person training  : https://www.linkedin.com/in/inancgumus/ | 
					
						
							|  |  |  | // Follow me on twitter: https://twitter.com/inancgumus | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package main | 
					
						
							| 
									
										
										
										
											2019-05-05 18:23:52 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"bufio" | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2019-05-06 01:30:56 +03:00
										 |  |  | 	"regexp" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2019-05-05 18:23:52 +03:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							|  |  |  | 	args := os.Args[1:] | 
					
						
							|  |  |  | 	if len(args) != 1 { | 
					
						
							|  |  |  | 		fmt.Println("Please type a search word.") | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	query := args[0] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 16:31:25 +03:00
										 |  |  | 	rx := regexp.MustCompile(`[^a-z]+`) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-05 18:23:52 +03:00
										 |  |  | 	in := bufio.NewScanner(os.Stdin) | 
					
						
							|  |  |  | 	in.Split(bufio.ScanWords) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	words := make(map[string]bool) | 
					
						
							|  |  |  | 	for in.Scan() { | 
					
						
							| 
									
										
										
										
											2019-05-06 01:30:56 +03:00
										 |  |  | 		word := strings.ToLower(in.Text()) | 
					
						
							|  |  |  | 		word = rx.ReplaceAllString(word, "") | 
					
						
							| 
									
										
										
										
											2019-05-06 16:31:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 01:30:56 +03:00
										 |  |  | 		if len(word) > 2 { | 
					
						
							|  |  |  | 			words[word] = true | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-05-05 18:23:52 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-06 01:30:56 +03:00
										 |  |  | 	// for word := range words { | 
					
						
							|  |  |  | 	// 	fmt.Println(word) | 
					
						
							|  |  |  | 	// } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-05 18:23:52 +03:00
										 |  |  | 	if words[query] { | 
					
						
							| 
									
										
										
										
											2019-05-05 19:04:27 +03:00
										 |  |  | 		fmt.Printf("The input contains %q.\n", query) | 
					
						
							| 
									
										
										
										
											2019-05-05 18:23:52 +03:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-05-06 16:31:25 +03:00
										 |  |  | 	fmt.Printf("Sorry. The input does not contain %q.\n", query) | 
					
						
							| 
									
										
										
										
											2019-05-05 19:04:27 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// query := "sun" | 
					
						
							|  |  |  | 	// fmt.Println("sun:", words["sun"], "tesla:", words["tesla"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// unnecessary | 
					
						
							|  |  |  | 	// if _, ok := words[query]; ok { | 
					
						
							|  |  |  | 	// 	fmt.Printf("The input contains %q.\n", query) | 
					
						
							|  |  |  | 	// 	return | 
					
						
							|  |  |  | 	// } | 
					
						
							| 
									
										
										
										
											2019-05-06 16:31:25 +03:00
										 |  |  | 	// fmt.Printf("Sorry. The input does not contain %q.\n", query) | 
					
						
							| 
									
										
										
										
											2019-05-05 18:23:52 +03:00
										 |  |  | } |