-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodejam_skeleton.py
71 lines (53 loc) · 2.01 KB
/
codejam_skeleton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import argparse
import fileinput
import functools
import logging
from typing import List
# Redefine the print function with flush=True. Needed for interactive problems.
print = functools.partial(print, flush=True)
# Configure logging
logging.basicConfig(
format='[%(lineno)03d]: %(message)s', level=logging.WARNING)
LOG = logging.getLogger(__name__)
def get_int() -> int:
"""Read an int from file or stdin."""
string = FILE.readline().strip()
return int(string)
def get_float() -> float:
"""Read a float from file or stdin."""
string = FILE.readline().strip()
return float(string)
def get_ints() -> List[int]:
"""Read multiple ints from file or stdin."""
string = FILE.readline().strip()
return [int(s) for s in string.split()]
def get_string() -> str:
"""Read a string from file or stdin."""
string = FILE.readline().strip()
return string
def main():
"""This is where you write your solution."""
cases = get_int()
for case in range(1, cases + 1):
# Your solution goes here
a = get_int()
print('Case #{}: {}'.format(case, a))
if __name__ == '__main__':
# Parse command line arguments
parser = argparse.ArgumentParser(description='Code Jam solution')
parser.add_argument('-v', '--verbose', action='count', default=0,
help="Increase verbosity. "
"Can be repeated up to two times.")
parser.add_argument('infile', default="-", nargs="?",
help="Read from file instead of stdin")
arguments = parser.parse_args()
# Possibly change logging level of the top-level logger
if arguments.verbose == 1:
logging.getLogger().setLevel(logging.INFO)
if arguments.verbose >= 2:
logging.getLogger().setLevel(logging.DEBUG)
# Print debugging information
LOG.debug("Finished parsing arguments: %s", arguments)
# Define a global FILE variable (sys.stdin or infile) and run main()
FILE = fileinput.input(files=arguments.infile)
main()