-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
92 lines (78 loc) · 1.62 KB
/
main.go
File metadata and controls
92 lines (78 loc) · 1.62 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"math/rand"
"time"
"github.com/atotto/clipboard"
)
func main(){
for{
var first,second int
fmt.Println()
fmt.Print("Enter Starting Difficulty: ")
fmt.Scanf("%d",&first)
fmt.Println()
fmt.Print("Enter Ending Difficulty: ")
fmt.Scanf("%d",&second)
fmt.Println()
if first>second{
fmt.Println("ENTER PROPPER OPTIONS!")
continue
}
res := getProblemUrl(first,second)
fmt.Println(res)
fmt.Println("Already Copied.")
clipboard.WriteAll(res)
}
}
func getProblemUrl(first,second int)string{
problems := []string{}
var url string
var LastsFirst string
var page int = 1
for {
url = fmt.Sprintf("https://codeforces.com/problemset/page/%d?tags=%d-%d",page,first,second)
resp,err := http.Get(url)
if err != nil{
fmt.Println(err)
}
body, err := ioutil.ReadAll(resp.Body)
if err!=nil{
panic(err)
}
s := string(body)
p := "/problemset/problem/"
indexes := []int{}
startIndex := 0
for {
index := strings.Index(s[startIndex:], p)
if index == -1 {
break
}
indexes = append(indexes, startIndex+index)
startIndex += index + len(p)
}
curProblems := []string{}
for i,v := range indexes{
if i%2 == 0{
index := strings.IndexRune(s[v:],'>')
index--
curProblems = append(curProblems, s[v:v+index])
}
}
if LastsFirst == curProblems[0]{
break
}
page++
LastsFirst = curProblems[0]
problems = append(problems,curProblems...)
}
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
i := r1.Intn(len(problems))
res := "https://codeforces.com"+problems[i]
return res
}