first commit

This commit is contained in:
2025-11-12 11:34:34 +03:00
commit 29280f3e50
77 changed files with 272246 additions and 0 deletions
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
a 2
aa 2
abc 2
ac 1
bcd 1
@@ -0,0 +1,5 @@
a 2
aa 2
abc 2
ac 1
bcd 1
@@ -0,0 +1,6 @@
a 2
aa 2
abc 2
ac 1
bcd 1
@@ -0,0 +1 @@
a aa abC aa ac abc bcd a
@@ -0,0 +1,2 @@
a 3
@@ -0,0 +1 @@
a 3
@@ -0,0 +1,2 @@
a 3
@@ -0,0 +1 @@
a A a
@@ -0,0 +1,10 @@
a 1
aaa 1
b 4
c 5
cc 1
ccc 1
d 2
f 1
r 1
@@ -0,0 +1,9 @@
a 1
aaa 1
b 4
c 5
cc 1
ccc 1
d 2
f 1
r 1
@@ -0,0 +1,10 @@
a 1
aaa 1
b 4
c 5
cc 1
ccc 1
d 2
f 1
r 1
@@ -0,0 +1 @@
c c f d aaA a c d r c ccc cC c b b b b
@@ -0,0 +1 @@
[{"status": "Ok"}, {"status": "Ok"}, {"status": "Ok"}]
+129
View File
@@ -0,0 +1,129 @@
#!/usr/bin/env python3
from json import load, dump, dumps
from glob import glob
from os import environ
from os.path import join
from sys import argv, exit
import os
import re
def run_single_test(data_dir, output_dir):
from task6 import check
with open(join(data_dir, 'input.txt')) as f:
check(f.read().strip(), join(output_dir, 'file.txt'))
def check_test(data_dir):
output_dir = os.path.join(data_dir, 'output')
gt_dir = os.path.join(data_dir, 'gt')
with open(join(output_dir, 'file.txt')) as f:
output = f.read().strip()
with open(join(gt_dir, 'file.txt')) as f:
gt = f.read().strip()
if output == gt:
res = f'Ok'
else:
res = f'Files are not the same'
if environ.get('CHECKER'):
print(res)
return res
def grade(data_dir):
results = load(open(join(data_dir, 'results.json')))
ok_count = 0
for result in results:
if result['status'] == 'Ok':
ok_count += 1
if ok_count == 3:
mark = 2
else:
mark = 0
total_count = len(results)
description = '%02d/%02d' % (ok_count, total_count)
res = {'description': description, 'mark': mark}
if environ.get('CHECKER'):
print(dumps(res))
return res
if __name__ == '__main__':
if environ.get('CHECKER'):
# Script is running in testing system
if len(argv) != 4:
print('Usage: %s mode data_dir output_dir' % argv[0])
exit(0)
mode, data_dir, output_dir = argv[1], argv[2], argv[3]
if mode == 'run_single_test':
run_single_test(data_dir, output_dir)
elif mode == 'check_test':
check_test(data_dir)
elif mode == 'grade':
grade(data_dir)
else:
# Script is running locally
if len(argv) != 2:
print(f'Usage: {argv[0]} tests_dir')
exit(0)
from glob import glob
from json import dump
from re import sub
from time import time
from traceback import format_exc
from os import makedirs
from os.path import basename, exists
from shutil import copytree
tests_dir = argv[1]
results = []
for input_dir in sorted(glob(join(tests_dir, '[0-9][0-9]_*_input'))):
output_dir = sub('input$', 'check', input_dir)
run_output_dir = join(output_dir, 'output')
makedirs(run_output_dir, exist_ok=True)
gt_src = sub('input$', 'gt', input_dir)
gt_dst = join(output_dir, 'gt')
if not exists(gt_dst):
copytree(gt_src, gt_dst)
try:
start = time()
run_single_test(input_dir, run_output_dir)
end = time()
running_time = end - start
except:
status = 'Runtime error'
traceback = format_exc()
else:
try:
status = check_test(output_dir)
except:
status = 'Checker error'
traceback = format_exc()
test_num = basename(input_dir)[:2]
if status == 'Runtime error' or status == 'Checker error':
print(test_num, status, '\n', traceback)
results.append({'status': status})
else:
results.append({'status': status})
dump(results, open(join(tests_dir, 'results.json'), 'w'))
res = grade(tests_dir)
print('Mark:', res['mark'], res['description'])
+11
View File
@@ -0,0 +1,11 @@
import collections
def check(line, name):
cnt = collections.Counter(line.lower().split())
with open(name, "w") as f:
for word in sorted(cnt):
f.write(f"{word} {cnt[word]}\n")
return
+12
View File
@@ -0,0 +1,12 @@
from collections import Counter
def check(line, file):
words = line.lower().split(" ")
counter = Counter(words)
with open(file, "w") as file:
for i in sorted(counter):
file.write(f"{i} {counter[i]}\n")
return