package main import sync strings fmt const strToSearch golang const co

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"sync"
"strings"
"fmt"
)
const strToSearch = `golang`
const countStreamMax = 5
var countFound int
func main() {
// Подготовка данных
urls := []string{
"qweqw",
"qwegolangqwe",
"adsda",
"cvdxbfghrgolang",
"vdrvdbvrt",
"ververwbve",
"vsvdfsvd",
"vsvdfvdvdfsvd",
"vsvdvdfvdffsvd",
"vsvdfsvdfvdvd",
}
for i := 0; i < 100; i++ {
urls = append(urls, urls[0:10]...)
}
c := make(chan string, 5)
var wg sync.WaitGroup
for i := 0; i < countStreamMax; i++ {
wg.Add(1)
go func() {
defer wg.Done()
readChan(c)
}()
}
for i := range urls {
c <- urls[i]
}
close(c)
wg.Wait()
fmt.Printf("Кол-во вхождений: %d", countFound)
}
func readChan(c <-chan string) {
for {
select {
case url, ok := <-c:
if ok {
if strings.Contains(url, strToSearch) {
countFound++
}
} else {
return
}
}
}
}