Created
November 2, 2015 13:04
-
-
Save avamsi/2c74e28e6a08c75ae31b to your computer and use it in GitHub Desktop.
Python code to generate HackerRank compatible zip file for test cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import random | |
| import sys | |
| import zipfile | |
| try: | |
| os.mkdir('input') | |
| os.mkdir('output') | |
| except OSError: | |
| pass | |
| tf = 10 # number of test files | |
| for i in xrange(1, tf + 1): | |
| print >>sys.stderr, 'Generating:', i | |
| sys.stdout = open('input/input%02d.txt' % i, 'wb') | |
| # | |
| # print test case(s) to input.txt | |
| # | |
| sys.stdout.close() | |
| # replace name by actual name in below block | |
| with zipfile.ZipFile('name.zip', 'w', zipfile.ZIP_DEFLATED) as zf: | |
| for i in xrange(1, tf + 1): | |
| print >>sys.stderr, 'Zipping:', i | |
| os.system('name < input/input%02d.txt > output/output%02d.txt' % (i, i)) | |
| zf.write('input/input%02d.txt' % i) | |
| zf.write('output/output%02d.txt' % i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment