本文整理汇总了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
}
//.........这里部分代码省略.........