From 99e2e923d0c77b02f3fb4ff648ea916954868606 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- .../life/lanqiao-selection-match/java-gen-out.rb | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 store/works/life/lanqiao-selection-match/java-gen-out.rb (limited to 'store/works/life/lanqiao-selection-match/java-gen-out.rb') diff --git a/store/works/life/lanqiao-selection-match/java-gen-out.rb b/store/works/life/lanqiao-selection-match/java-gen-out.rb new file mode 100755 index 0000000..bedad2d --- /dev/null +++ b/store/works/life/lanqiao-selection-match/java-gen-out.rb @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby + +require 'timeout' + +def run(no, count) + Dir.glob("./codes/*#{no}.java").each do |f| + code = File.read(f) + code.sub!(/public\s+class\s+\S+/, 'public class Main') + + java_file = f.sub('codes', 'temp') + + File.write(java_file, code) + + count.times do |i| + in_file = "./generator/#{no}-#{i + 1}.in" + out_file = "#{f.sub('codes', 'out').sub('.java', '')}-#{i + 1}.out" + pid = Process.spawn "/usr/local/opt/openjdk/bin/java #{java_file} < #{in_file} > #{out_file}" + Timeout.timeout(5) do + Process.wait pid + end + rescue Timeout::Error + puts "Timeout for #{f} when tests #{i + 1} case" + File.delete out_file + Process.kill 'KILL', pid + end + rescue StandardError + puts "Error for #{f}" + end +end + +run 'A', 3 +run 'B', 3 +run 'C', 4 -- cgit v1.2.3