From c1b6459cf8ae304a572d744eabc58f41582640cf Mon Sep 17 00:00:00 2001 From: Tanphoon <2979283542@qq.com> Date: Sat, 15 Jul 2023 12:56:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E8=A7=A3=E5=86=B3ma?= =?UTF-8?q?keData=E6=97=B6=E6=9C=89=E9=BB=91=E6=A1=86=E9=97=AA=E5=8A=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProgramCompareUI.py | 10 +++++++--- README.md | 24 ++++++++++++++++++++++++ setData.py | 14 ++++++++------ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ProgramCompareUI.py b/ProgramCompareUI.py index 4be2970..07ed2ea 100644 --- a/ProgramCompareUI.py +++ b/ProgramCompareUI.py @@ -27,7 +27,8 @@ def __del__(self): def compare(self, id: int = 1, show_input=True, show_output=True): # 产生样例输入 with open(f'test{id}.in', 'w') as file: - self.setData(file, id) + writeln = lambda a : file.write(' '.join(map(str, a)) + '\n') + self.setData(writeln, id) # 获取样例答案和样例输出 std_out = os.popen(self.std_exe + ' < ' + f'test{id}.in').read() cmp_out = os.popen(self.cmp_exe + ' < ' + f'test{id}.in').read() @@ -50,5 +51,8 @@ def compare(self, id: int = 1, show_input=True, show_output=True): def makeData(self, id: int = 1): # 使用setData产生样例输入并用std_exe产生样例答案 with open(f'test{id}.in', 'w') as file: - self.setData(file, id) - os.system(f'{self.std_exe} < test{id}.in > test{id}.out') \ No newline at end of file + writeln = lambda a : file.write(' '.join(map(str, a)) + '\n') + self.setData(writeln, id) + with open(f'test{id}.out', 'w') as file: + std_out = os.popen(self.std_exe + ' < ' + f'test{id}.in').read() + file.write(std_out) \ No newline at end of file diff --git a/README.md b/README.md index a8886c6..43771c7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,31 @@ # program-compare-UI +A program-comparer Based on PyQt5. + +## Usage + ![](img/GUI.png) +### prepare `setData.py` + +`writeln` Pass in a list and write it on one line. + +```python +from random import randint + + +def randPair(a, b): + l = randint(a, b) + r = randint(a, b) + return (l, r) if l < r else (r, l) + + +def setData(writeln, id=1): + a = randint(1, 2e9) + b = randint(1, 2e9) + writeln([a, b]) +``` + # program-compare This is a program-comparer for programming competition. It's base on `cyaron`, but some simple encapsulation was made. diff --git a/setData.py b/setData.py index 27ed6d9..df647f6 100644 --- a/setData.py +++ b/setData.py @@ -1,11 +1,13 @@ -from io import TextIOWrapper from random import randint -def setData(file: TextIOWrapper, id=1): - write = lambda *x: file.write(' '.join([str(i) for i in x]) + ' ') - writeln = lambda *x: file.write(' '.join([str(i) for i in x]) + '\n') - ################### +def randPair(a, b): + l = randint(a, b) + r = randint(a, b) + return (l, r) if l < r else (r, l) + + +def setData(writeln, id=1): a = randint(1, 2e9) b = randint(1, 2e9) - writeln(a, b) \ No newline at end of file + writeln([a, b]) \ No newline at end of file