当前位置: 首页>>代码示例>>Golang>>正文


Golang ProblemArchiveReader.Glob方法代码示例

本文整理汇总了Golang中github.com/lanior/upc/formats.ProblemArchiveReader.Glob方法的典型用法代码示例。如果您正苦于以下问题:Golang ProblemArchiveReader.Glob方法的具体用法?Golang ProblemArchiveReader.Glob怎么用?Golang ProblemArchiveReader.Glob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/lanior/upc/formats.ProblemArchiveReader的用法示例。


在下文中一共展示了ProblemArchiveReader.Glob方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ImportArchive

func (self Format) ImportArchive(archive *formats.ProblemArchiveReader) (problems []*model.Problem, err error) {
	defer SuppressPanic(&err)

	files := archive.Glob("*.xml")
	PanicIf(len(files) == 0, "Task file not found")
	PanicIf(len(files) > 1, "Several xml files found in the archive")

	reader, err := archive.Open(files[0])
	PanicIf(err)
	defer reader.Close()

	container := new(Container)
	utils.NewXmlDecoder(reader).Decode(container)

	problem := container.Problem
	PanicIf(problem == nil, "Problem node not found")

	p := &model.Problem{
		Title:  problem.Title,
		Author: problem.Author,

		TimeLimit:   float32(problem.TimeLimit),
		MemoryLimit: float32(problem.MemoryLimit),

		Statement:    parseSGML(problem.Statement),
		Constraints:  parseSGML(problem.Constraints),
		InputFormat:  parseSGML(problem.InputFormat),
		OutputFormat: parseSGML(problem.OutputFormat),

		Generators: make(map[string]*model.Generator),
		Solutions:  make(map[string]*model.Solution),
		Images:     make(model.ImagesDict),
	}

	getSample := func(res *SampleResource) string {
		if res.Source != "" {
			data, err := archive.ReadFile(res.Source)
			PanicIf(err)
			return string(data)
		}
		return res.Text
	}

	p.Samples = make([]model.Sample, len(problem.Samples))
	for i, sample := range problem.Samples {
		p.Samples[i].Input = getSample(&sample.SampleIn)
		p.Samples[i].Output = getSample(&sample.SampleOut)
	}

	for _, picture := range problem.Pictures {
		data, err := archive.ReadFile(picture.Source)
		PanicIf(err)
		p.Images[picture.Name] = data
	}

	for _, generator := range problem.Generators {
		addGenerator(archive, p, &generator)
	}

	for _, genRange := range problem.GeneratorRanges {
		for j := genRange.From; j <= genRange.To; j++ {
			generator := genRange.Generator
			generator.Name = applyTestRank(generator.Name, j)
			generator.Source = applyTestRank(generator.Source, j)
			addGenerator(archive, p, &generator)
		}
	}

	for _, solution := range problem.Solutions {
		lang := getLanguage(solution.LanguageCode, solution.Source)
		PanicIf(lang == nil, "Unknown solution language")

		data, err := archive.ReadFile(solution.Source)
		PanicIf(err)

		p.Solutions[solution.Name] = &model.Solution{
			Name:       solution.Name,
			Language:   lang.Name,
			SourceCode: string(data),
		}
	}

	convertTest := func(t *model.Test, test *Test) {
		t.Points = test.Points

		if in := test.InputFile; in != nil {
			if in.Source != "" {
				data, err := archive.ReadFile(in.Source)
				PanicIf(err)

				t.Input = model.ConstTestData(data)
			} else if in.Generator != "" || in.Parameters != "" {
				if t.Input == nil {
					t.Input = &model.GeneratedInput{}
				}

				if in.Generator != "" {
					t.Input.(*model.GeneratedInput).Generator = in.Generator
				}

//.........这里部分代码省略.........
开发者ID:lanior,项目名称:upc,代码行数:101,代码来源:import.go


注:本文中的github.com/lanior/upc/formats.ProblemArchiveReader.Glob方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。