inital commit 1
This commit is contained in:
commit
db645123c7
196 files changed
+11102
No files matched your search
Whitespace-only changes.
+145
@@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<fps version="1.2" url="https://github.com/zhblue/freeproblemset/">
|
||||
<generator name="HUSTOJ" url="https://github.com/zhblue/hustoj/"/>
|
||||
<item>
|
||||
<title><![CDATA[A+B Problem]]></title>
|
||||
<time_limit unit="s"><![CDATA[1]]></time_limit>
|
||||
<memory_limit unit="mb"><![CDATA[256]]></memory_limit>
|
||||
|
||||
<img><src><![CDATA[http://vd.hustoj.com:80/upload/image/20170219/20170219102428_18727.png]]></src><base64><![CDATA[iVBORw0KGgoAAAANSUhEUgAAABUAAAARCAYAAAAyhueAAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAACw2lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpwaG90b3Nob3A9Imh0dHA6Ly9ucy5hZG9iZS5jb20vcGhvdG9zaG9wLzEuMC8iCiAgICAgICAgICAgIHhtbG5zOmV4aWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vZXhpZi8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDxwaG90b3Nob3A6RGF0ZUNyZWF0ZWQ+MjAxNy0wMS0xNFQxMDo1MzowNTwvcGhvdG9zaG9wOkRhdGVDcmVhdGVkPgogICAgICAgICA8ZXhpZjpVc2VyQ29tbWVudD4KICAgICAgICAgICAgPHJkZjpBbHQ+CiAgICAgICAgICAgICAgIDxyZGY6bGkgeG1sOmxhbmc9IngtZGVmYXVsdCI+U2NyZWVuc2hvdDwvcmRmOmxpPgogICAgICAgICAgICA8L3JkZjpBbHQ+CiAgICAgICAgIDwvZXhpZjpVc2VyQ29tbWVudD4KICAgICAgICAgPHRpZmY6T3JpZW50YXRpb24+MTwvdGlmZjpPcmllbnRhdGlvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cjlo66MAAAApSURBVDgRY/wPBAxUBkxUNg9s3Kih1A/V0TAdDVMqh8BokqJygAKNAwDaWgQehTZHywAAAABJRU5ErkJggg==]]></base64></img><description><![CDATA[test<img src="http://vd.hustoj.com:80/upload/image/20170219/20170219102428_18727.png" alt="" />]]></description>
|
||||
<input><![CDATA[<p>
|
||||
Two integer a,b (0<=a,b<=10)
|
||||
</p>]]></input>
|
||||
<output><![CDATA[<p>
|
||||
Output a+b
|
||||
</p>]]></output>
|
||||
<sample_input><![CDATA[1 2]]></sample_input>
|
||||
<sample_output><![CDATA[3]]></sample_output>
|
||||
<test_input><![CDATA[500 17
|
||||
]]></test_input>
|
||||
<test_output><![CDATA[517]]></test_output>
|
||||
<test_input><![CDATA[1 2
|
||||
|
||||
]]></test_input>
|
||||
<test_output><![CDATA[3
|
||||
]]></test_output>
|
||||
<hint><![CDATA[hint]]></hint>
|
||||
<source><![CDATA[系统原理,熟悉OJ]]></source>
|
||||
<solution language="C"><![CDATA[#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
while(scanf("%d%d",&a,&b)!=EOF)
|
||||
{
|
||||
printf("%d\n",a+b);
|
||||
}
|
||||
return 0;
|
||||
}]]></solution>
|
||||
<template language="C"><![CDATA[#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
scanf("%d %d",&a,&b);
|
||||
printf("%d",a+b);
|
||||
return 0;
|
||||
}
|
||||
]]></template>
|
||||
<solution language="C++"><![CDATA[#include <iostream>
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
#ifndef ONLINE_JUDGE
|
||||
freopen("in.txt","r",stdin);
|
||||
#endif
|
||||
int a,b;
|
||||
while(cin >>a >>b)
|
||||
{
|
||||
cout <<a+b <<endl;
|
||||
}
|
||||
return 0;
|
||||
}]]></solution>
|
||||
<template language="C++"><![CDATA[#include <iostream>
|
||||
using namespace std;
|
||||
int main(){
|
||||
int a,b;
|
||||
while(cin >> a >> b)
|
||||
cout << a+b << endl;
|
||||
return 0;
|
||||
}
|
||||
]]></template>
|
||||
<solution language="Pascal"><![CDATA[program abprob;
|
||||
var
|
||||
a,b:longint;
|
||||
begin
|
||||
readln(a,b);
|
||||
writeln(a+b);
|
||||
end.]]></solution>
|
||||
<solution language="Java"><![CDATA[import java.util.*;
|
||||
public class Main
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
Scanner cin = new Scanner(System.in);
|
||||
int a,b;
|
||||
|
||||
while(cin.hasNextInt())
|
||||
{
|
||||
a = cin.nextInt();
|
||||
b = cin.nextInt();
|
||||
System.out.println(a+b);
|
||||
}
|
||||
}
|
||||
}]]></solution>
|
||||
<prepend language="Java"><![CDATA[import java.io.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main
|
||||
|
||||
{
|
||||
]]></prepend>
|
||||
<append language="Java"><![CDATA[ public static void main(String args[]) throws Exception
|
||||
|
||||
{
|
||||
|
||||
Scanner cin=new Scanner(System.in);
|
||||
while(cin.hasNextInt()){
|
||||
int a=cin.nextInt();
|
||||
int b=cin.nextInt();
|
||||
System.out.println(plus_2_int(a,b));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}]]></append>
|
||||
<template language="Python"><![CDATA[a = input()
|
||||
a = a.split()
|
||||
b = []
|
||||
for i in a:
|
||||
b.append(int(i))
|
||||
print (sum(b))
|
||||
]]></template>
|
||||
<template language="Clang"><![CDATA[#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
scanf("%d %d",&a,&b);
|
||||
printf("%d",a+b);
|
||||
return 0;
|
||||
}
|
||||
]]></template>
|
||||
<template language="Clang++"><![CDATA[#include <iostream>
|
||||
using namespace std;
|
||||
int main(){
|
||||
int a,b;
|
||||
while(cin >> a >> b)
|
||||
cout << a+b << endl;
|
||||
return 0;
|
||||
}
|
||||
]]></template>
|
||||
<spj language="C"><![CDATA[ii
|
||||
]]></spj></item>
|
||||
</fps>
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
#!/usr/bin/env python3
|
||||
import base64
|
||||
import copy
|
||||
import random
|
||||
import string
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
class FPSParser(object):
|
||||
def __init__(self, fps_path=None, string_data=None):
|
||||
if fps_path:
|
||||
self._etree = ET.parse(fps_path).getroot()
|
||||
elif string_data:
|
||||
self._ertree = ET.fromstring(string_data).getroot()
|
||||
else:
|
||||
raise ValueError("You must tell me the file path or directly give me the data for the file")
|
||||
version = self._etree.attrib.get("version", "No Version")
|
||||
if version not in ["1.1", "1.2"]:
|
||||
raise ValueError("Unsupported version '" + version + "'")
|
||||
|
||||
@property
|
||||
def etree(self):
|
||||
return self._etree
|
||||
|
||||
def parse(self):
|
||||
ret = []
|
||||
for node in self._etree:
|
||||
if node.tag == "item":
|
||||
ret.append(self._parse_one_problem(node))
|
||||
return ret
|
||||
|
||||
def _parse_one_problem(self, node):
|
||||
sample_start = True
|
||||
test_case_start = True
|
||||
problem = {"title": "No Title", "description": "No Description",
|
||||
"input": "No Input Description",
|
||||
"output": "No Output Description",
|
||||
"memory_limit": {"unit": None, "value": None},
|
||||
"time_limit": {"unit": None, "value": None},
|
||||
"samples": [], "images": [], "append": [],
|
||||
"template": [], "prepend": [], "test_cases": [],
|
||||
"hint": None, "source": None, "spj": None, "solution": []}
|
||||
for item in node:
|
||||
tag = item.tag
|
||||
if tag in ["title", "description", "input", "output", "hint", "source"]:
|
||||
problem[item.tag] = item.text
|
||||
elif tag == "time_limit":
|
||||
unit = item.attrib.get("unit", "s")
|
||||
if unit not in ["s", "ms"]:
|
||||
raise ValueError("Invalid time limit unit")
|
||||
problem["time_limit"]["unit"] = item.attrib.get("unit", "s")
|
||||
value = int(item.text)
|
||||
if value <= 0:
|
||||
raise ValueError("Invalid time limit value")
|
||||
problem["time_limit"]["value"] = value
|
||||
elif tag == "memory_limit":
|
||||
unit = item.attrib.get("unit", "MB")
|
||||
if unit not in ["MB", "KB", "mb", "kb"]:
|
||||
raise ValueError("Invalid memory limit unit")
|
||||
problem["memory_limit"]["unit"] = unit.upper()
|
||||
value = int(item.text)
|
||||
if value <= 0:
|
||||
raise ValueError("Invalid memory limit value")
|
||||
problem["memory_limit"]["value"] = value
|
||||
elif tag in ["template", "append", "prepend", "solution"]:
|
||||
lang = item.attrib.get("language")
|
||||
if not lang:
|
||||
raise ValueError("Invalid " + tag + ", language name is missed")
|
||||
problem[tag].append({"language": lang, "code": item.text})
|
||||
elif tag == "spj":
|
||||
lang = item.attrib.get("language")
|
||||
if not lang:
|
||||
raise ValueError("Invalid spj, language name if missed")
|
||||
problem["spj"] = {"language": lang, "code": item.text}
|
||||
elif tag == "img":
|
||||
problem["images"].append({"src": None, "blob": None})
|
||||
for child in item:
|
||||
if child.tag == "src":
|
||||
problem["images"][-1]["src"] = child.text
|
||||
elif child.tag == "base64":
|
||||
problem["images"][-1]["blob"] = base64.b64decode(child.text)
|
||||
elif tag == "sample_input":
|
||||
if not sample_start:
|
||||
raise ValueError("Invalid xml, error 'sample_input' tag order")
|
||||
problem["samples"].append({"input": item.text, "output": None})
|
||||
sample_start = False
|
||||
elif tag == "sample_output":
|
||||
if sample_start:
|
||||
raise ValueError("Invalid xml, error 'sample_output' tag order")
|
||||
problem["samples"][-1]["output"] = item.text
|
||||
sample_start = True
|
||||
elif tag == "test_input":
|
||||
if not test_case_start:
|
||||
raise ValueError("Invalid xml, error 'test_input' tag order")
|
||||
problem["test_cases"].append({"input": item.text, "output": None})
|
||||
test_case_start = False
|
||||
elif tag == "test_output":
|
||||
if test_case_start:
|
||||
raise ValueError("Invalid xml, error 'test_output' tag order")
|
||||
problem["test_cases"][-1]["output"] = item.text
|
||||
test_case_start = True
|
||||
|
||||
return problem
|
||||
|
||||
|
||||
class FPSHelper(object):
|
||||
def save_image(self, problem, base_dir, base_url):
|
||||
_problem = copy.deepcopy(problem)
|
||||
for img in _problem["images"]:
|
||||
name = "".join(random.choice(string.ascii_lowercase + string.digits) for _ in range(12))
|
||||
ext = os.path.splitext(img["src"])[1]
|
||||
file_name = name + ext
|
||||
with open(os.path.join(base_dir, file_name), "wb") as f:
|
||||
f.write(img["blob"])
|
||||
for item in ["description", "input", "output"]:
|
||||
_problem[item] = _problem[item].replace(img["src"], os.path.join(base_url, file_name))
|
||||
return _problem
|
||||
|
||||
# {
|
||||
# "spj": false,
|
||||
# "test_cases": {
|
||||
# "1": {
|
||||
# "stripped_output_md5": "84f244e41d3c8fd4bdb43ed0e1f7a067",
|
||||
# "input_size": 12,
|
||||
# "output_size": 7,
|
||||
# "input_name": "1.in",
|
||||
# "output_name": "1.out"
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
def save_test_case(self, problem, base_dir):
|
||||
spj = problem.get("spj", {})
|
||||
test_cases = {}
|
||||
for index, item in enumerate(problem["test_cases"]):
|
||||
input_content = item.get("input")
|
||||
output_content = item.get("output")
|
||||
if input_content:
|
||||
with open(os.path.join(base_dir, str(index + 1) + ".in"), "w", encoding="utf-8") as f:
|
||||
f.write(input_content)
|
||||
if output_content:
|
||||
with open(os.path.join(base_dir, str(index + 1) + ".out"), "w", encoding="utf-8") as f:
|
||||
f.write(output_content)
|
||||
if spj:
|
||||
one_info = {
|
||||
"input_size": len(input_content),
|
||||
"input_name": f"{index + 1}.in"
|
||||
}
|
||||
else:
|
||||
one_info = {
|
||||
"input_size": len(input_content),
|
||||
"input_name": f"{index + 1}.in",
|
||||
"output_size": len(output_content),
|
||||
"output_name": f"{index + 1}.out",
|
||||
"stripped_output_md5": hashlib.md5(output_content.rstrip().encode("utf-8")).hexdigest()
|
||||
}
|
||||
test_cases[index] = one_info
|
||||
info = {
|
||||
"spj": True if spj else False,
|
||||
"test_cases": test_cases
|
||||
}
|
||||
with open(os.path.join(base_dir, "info"), "w", encoding="utf-8") as f:
|
||||
f.write(json.dumps(info, indent=4))
|
||||
return info
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import pprint
|
||||
|
||||
parser = FPSParser("fps.xml")
|
||||
helper = FPSHelper()
|
||||
problems = parser.parse()
|
||||
for index, problem in enumerate(problems):
|
||||
path = os.path.join("/tmp/", str(index + 1))
|
||||
os.mkdir(path)
|
||||
helper.save_test_case(problem, path)
|
||||
|
||||
pprint.pprint(helper.save_image(problem, "/tmp", "/static/img"))
|
||||
Reference in new issue
Block a user