-
Notifications
You must be signed in to change notification settings - Fork 19
/
47. Code Jam.py
58 lines (37 loc) · 1.41 KB
/
47. Code Jam.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
'''
Below links have the Google Code Jam qualification round practice problems.
1. https://code.google.com/codejam/contest/351101/dashboard#s=p0
2. https://code.google.com/codejam/contest/351101/dashboard#s=p1
'''
#1st Problem - Store Credit
def solve(path,out):
f = open(path, 'r')
o = open(out, 'w')
test_cases = int(f.readline())
for c in range(test_cases):
credit = int(f.readline())
items = int(f.readline())
nos = map(int, f.readline().rstrip().split(' '))
for i in range(items):
for j in range(i+1, items):
if nos[i] + nos[j] ==credit:
o.write('Case #{}: {} {}\n'.format(c+1, i+1, j+1))
break
f.close()
o.close()
# Replace with your file input and output paths
solve('C:\Users\my\Desktop\A-Large-practice.in',
'C:\Users\my\Desktop\A-Large-practice.out')
# 2nd Problem - Reverse words
def solve(path,out):
f = open(path, 'r')
o = open(out, 'w')
test_cases = int(f.readline())
for c in range(test_cases):
line = f.readline().split()
print line
print 'Case #{}: {}\n'.format(c+1, ' '.join(line[::-1]))
o.write('Case #{}: {}\n'.format(c+1, ' '.join(line[::-1])))
#replace with your file input and output paths
solve('C:\Users\my\Desktop\B-large-practice.in',
'C:\Users\my\Desktop\B-large-practice.out')