Пример #1
0
func (self Format) ImportArchive(archive *formats.ProblemArchiveReader) (problems []*model.Problem, err error) {
	defer SuppressPanic(&err)

	p := &model.Problem{
		Solutions: make(map[string]*model.Solution),
	}
	PanicIf(archive.LoadTests(p, "in/(.*).in$", "out/(.*).out$"))
	PanicIf(archive.LoadSolutions(p, "prog/(.*)"))
	return []*model.Problem{p}, nil
}
Пример #2
0
func (self Format) ImportArchive(archive *formats.ProblemArchiveReader) (problems []*model.Problem, err error) {
	defer SuppressPanic(&err)

	data, err := archive.ReadFile("domjudge-problem.ini")
	PanicIf(err, "Cannot read problem settings: %s", err)

	settings := ParseSettings(data)

	p := &model.Problem{
		Title:       settings["name"],
		TimeLimit:   float32(settings.GetInt("timelimit")),
		MemoryLimit: 128,

		Solutions: make(map[string]*model.Solution),
	}

	PanicIf(archive.LoadTests(p, "(.*).in$", "(.*).out$"))
	PanicIf(archive.LoadSolutions(p, "sol_(.*)"))
	return []*model.Problem{p}, nil
}
Пример #3
0
func (self Format) ImportArchive(archive *formats.ProblemArchiveReader) (problems []*model.Problem, err error) {
	defer SuppressPanic(&err)

	file, err := archive.Open("conf/serve.cfg")
	PanicIf(err, "Cannot open contest config: %s", err)
	defer file.Close()

	config, err := ReadConfig(file)
	PanicIf(err, "Cannot read contest config: %s", err)

	problemsData := make(map[string]*Section)

	global := &Section{Values: make(ValuesMap)}

	getGlobal := func(key, defaultValue string) string {
		value, ok := global.Values[key]
		if !ok {
			return defaultValue
		}
		return value
	}

	for i, section := range config {
		if section.Name == "problem" {
			problemsData[section.Values["short_name"]] = &config[i]
		} else if section.Name == "" {
			global = &config[i]
		}
	}

	for _, problem := range problemsData {
		if problem.Values["abstract"] == "1" {
			continue
		}

		getValue := func(key, defaultValue string) string {
			value, ok := problem.Values[key]
			if !ok {
				super := problem.Values["super"]
				if parentProblem := problemsData[super]; parentProblem != nil {
					value, ok := parentProblem.Values[key]
					if !ok {
						return defaultValue
					}
					return value
				}
			}
			return value
		}

		p := &model.Problem{
			Title:       getValue("long_name", ""),
			TimeLimit:   float32(getInt(getValue("time_limit", "0"))),
			MemoryLimit: float32(getMemory(getValue("max_vm_size", "0")) / 1024 / 1024),
			Solutions:   make(map[string]*model.Solution),
		}

		if getValue("use_stdin", "false") != "false" {
			p.InputFile = "*STDIN"
		} else {
			p.InputFile = getValue("input_file", "input")
		}

		if getValue("use_stdout", "false") != "false" {
			p.OutputFile = "*STDOUT"
		} else {
			p.OutputFile = getValue("output_file", "output")
		}

		shortName := getValue("short_name", "")

		testSfx := getValue("test_sfx", global.Values["test_sfx"])
		corrSfx := getValue("corr_sfx", global.Values["corr_sfx"])

		var testDir, corrDir, solDir, statementPath string
		if getGlobal("advanced_layout", "0") == "1" {
			testDir = filepath.Join("problems", shortName, "tests")
			corrDir = testDir
			solDir = filepath.Join("problems", shortName, "solutions")
			statementPath = filepath.Join("problems", shortName, "statement.xml")
		} else {
			Panic("Unsupported problems layout")
		}

		testPattern := fmt.Sprintf("%s/(.*)%s$", testDir, testSfx)
		resultPattern := fmt.Sprintf("%s/(.*)%s$", corrDir, corrSfx)
		solutionPattern := fmt.Sprintf("%s/(.*)$", solDir)

		PanicIf(archive.LoadTests(p, testPattern, resultPattern))
		PanicIf(archive.LoadSolutions(p, solutionPattern))

		statementFile, err := archive.Open(statementPath)
		PanicIf(err, "Cannot open statement file")
		defer statementFile.Close()

		problem := new(Problem)
		utils.NewXmlDecoder(statementFile).Decode(problem)

		p.Samples = make([]model.Sample, len(problem.Examples.Items))
		for i, example := range problem.Examples.Items {
			p.Samples[i].Input = example.Input
			p.Samples[i].Output = example.Output
		}

		p.Title = problem.Statement.Title
		p.Statement = parseHTML(problem.Statement.Description.Text)
		p.InputFormat = parseHTML(problem.Statement.InputFormat.Text)
		p.OutputFormat = parseHTML(problem.Statement.OutputFormat.Text)

		problems = append(problems, p)
	}

	return problems, nil
}