Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue with generating the in1.txt of a problem #174 #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion client/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ func findSample(body []byte) (input [][]byte, output [][]byte, err error) {
return
}


func stripHTMLTags(input string) string {
// Split the content by div tags and trim spaces
sections := regexp.MustCompile(`(?i)<div[^>]*>`).Split(input, -1)
var cleanSections []string
for _, section := range sections {
// Remove closing </div> tag and trim spaces
section = strings.TrimSpace(regexp.MustCompile(`(?i)</div>`).ReplaceAllString(section, ""))
if section != "" {
cleanSections = append(cleanSections, section)
}
}
// Join the sections with newlines
return html.UnescapeString(strings.Join(cleanSections, "\n"))
}

// ParseProblem parse problem to path. mu can be nil
func (c *Client) ParseProblem(URL, path string, mu *sync.Mutex) (samples int, standardIO bool, err error) {
body, err := util.GetBody(c.client, URL)
Expand All @@ -64,7 +80,8 @@ func (c *Client) ParseProblem(URL, path string, mu *sync.Mutex) (samples int, st
for i := 0; i < len(input); i++ {
fileIn := filepath.Join(path, fmt.Sprintf("in%v.txt", i+1))
fileOut := filepath.Join(path, fmt.Sprintf("ans%v.txt", i+1))
e := ioutil.WriteFile(fileIn, input[i], 0644)
cleanInput := stripHTMLTags(string(input[i]))
e := ioutil.WriteFile(fileIn, []byte(cleanInput), 0644)
if e != nil {
if mu != nil {
mu.Lock()
Expand Down