本文整理匯總了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
}
//.........這裏部分代碼省略.........