Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 68dc890

Browse files
Convert Python 2 code to Python 3
1 parent acdbf41 commit 68dc890

File tree

254 files changed

+2742
-2409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

254 files changed

+2742
-2409
lines changed

‎DMOJ/aplusb.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Ivan Carvalho
22
# Solution to https://dmoj.ca/problem/aplusb
33
import sys
4+
45
raw_input = sys.stdin.readline
5-
tc = int(raw_input())
6+
tc = int(input())
67
while tc:
78
tc -= 1
8-
a,b = [int(i) for i in raw_input().split()]
9-
printa + b
9+
a,b = [int(i) for i in input().split()]
10+
print(a + b)

‎DMOJ/bf1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# Solution to https://dmoj.ca/problem/bf1
33
#!/usr/bin/env python2.7
44
# -*- coding : utf-8 -*-
5-
a = int(raw_input())
5+
a = int(input())
66
v = []
7-
for i in xrange(a):
8-
j = int(raw_input())
9-
v.append(j)
7+
for i in range(a):
8+
j = int(input())
9+
v.append(j)
1010
v.sort()
1111
for i in v:
12-
printi
12+
print(i)

‎DMOJ/bf1hard.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#!/usr/bin/env python2.7
44
# -*- coding : utf-8 -*-
55
from sys import stdin
6+
67
raw_input = stdin.readline
7-
a = int(raw_input())
8+
a = int(input())
89
v = []
9-
for i in xrange(a):
10-
j = int(raw_input())
11-
v.append(j)
10+
for i in range(a):
11+
j = int(input())
12+
v.append(j)
1213
v.sort()
1314
for i in v:
14-
printi
15+
print(i)

‎DMOJ/boolean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# Solution to https://dmoj.ca/problem/boolean
33
#!/usr/bin/env python2.7
44
# -*- coding : utf-8 -*-
5-
a = raw_input()
6-
printeval(a)
5+
a = input()
6+
print(eval(a))

‎DMOJ/ccc10j5.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,37 @@
33
#!/usr/bin/env python2.7
44
# -*- coding : utf-8 -*-
55
from collections import deque
6-
def bfs(graph,start,end):
7-
visited = set()
8-
queue = deque([(0,start)])
9-
while queue:
10-
distance,v = queue.popleft()
11-
if v == end:
12-
return distance
13-
if v not in visited:
14-
visited.add(v)
15-
for i in graph.get(v,[]):
16-
queue.append((distance+1,i))
17-
return -1
18-
dicio = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8}
6+
7+
8+
def bfs(graph, start, end):
9+
visited = set()
10+
queue = deque([(0, start)])
11+
while queue:
12+
distance, v = queue.popleft()
13+
if v == end:
14+
return distance
15+
if v not in visited:
16+
visited.add(v)
17+
for i in graph.get(v, []):
18+
queue.append((distance + 1, i))
19+
return -1
20+
21+
22+
dicio = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8}
1923
grafo = {}
20-
for i in xrange(1,9):
21-
for j in xrange(1,9):
22-
complexo = complex(i,j)
23-
grafo[complexo] = [complexo+complex(1,2),complexo+complex(-1,2),complexo+complex(1,-2),complexo+complex(-1,-2),complexo+complex(2,1),complexo+complex(2,-1),complexo+complex(-2,1),complexo+complex(-2,-1)]
24-
a,b = [int(i) for i in raw_input().split()]
25-
c,d = [int(i) for i in raw_input().split()]
26-
print bfs(grafo,complex(a,b),complex(c,d))
24+
for i in range(1, 9):
25+
for j in range(1, 9):
26+
complexo = complex(i, j)
27+
grafo[complexo] = [
28+
complexo + complex(1, 2),
29+
complexo + complex(-1, 2),
30+
complexo + complex(1, -2),
31+
complexo + complex(-1, -2),
32+
complexo + complex(2, 1),
33+
complexo + complex(2, -1),
34+
complexo + complex(-2, 1),
35+
complexo + complex(-2, -1),
36+
]
37+
a, b = [int(i) for i in input().split()]
38+
c, d = [int(i) for i in input().split()]
39+
print(bfs(grafo, complex(a, b), complex(c, d)))

‎DMOJ/ccc96s4.py

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
11
# Ivan Carvalho
22
# Solution to https://dmoj.ca/problem/ccc96s4
3-
#!/usr/bin/env python2.7
3+
#!/usr/bin/env python2.7
44
# -*- coding : utf-8 -*-
55
def to_roman(entrada):
6-
array = []
7-
for a,b in [("M",1000),("CM",900),("D",500),("CD",400),("C",100),("XC",90),("L",50),("XL",40),("X",10),("IX",9),("V",5),("IV",4),("I",1)]:
8-
total = int(entrada/b)
9-
for k in xrange(total):
10-
array.append(a)
11-
entrada %= b
12-
return "".join(array)
6+
array = []
7+
for a, b in [
8+
("M", 1000),
9+
("CM", 900),
10+
("D", 500),
11+
("CD", 400),
12+
("C", 100),
13+
("XC", 90),
14+
("L", 50),
15+
("XL", 40),
16+
("X", 10),
17+
("IX", 9),
18+
("V", 5),
19+
("IV", 4),
20+
("I", 1),
21+
]:
22+
total = int(entrada / b)
23+
for k in range(total):
24+
array.append(a)
25+
entrada %= b
26+
return "".join(array)
27+
28+
1329
mapa = {}
14-
for i in xrange(1,1001):
15-
mapa[to_roman(i)] = i
16-
casos = int(raw_input())
17-
for vez in xrange(casos):
18-
a,b = raw_input().replace("+"," ").replace("=","").split()
19-
xa = 1001
20-
if a in mapa:
21-
xa = mapa[a]
22-
xb = 1001
23-
if b in mapa:
24-
xb = mapa[b]
25-
resultado = xa+xb
26-
if resultado <= 1000:
27-
print"%s+%s=%s" % (a,b,to_roman(resultado))
28-
else:
29-
print"%s+%s=CONCORDIA CUM VERITATE" % (a,b)
30+
for i in range(1,1001):
31+
mapa[to_roman(i)] = i
32+
casos = int(input())
33+
for vez in range(casos):
34+
a, b = input().replace("+"," ").replace("=","").split()
35+
xa = 1001
36+
if a in mapa:
37+
xa = mapa[a]
38+
xb = 1001
39+
if b in mapa:
40+
xb = mapa[b]
41+
resultado = xa+xb
42+
if resultado <= 1000:
43+
print("%s+%s=%s" % (a,b, to_roman(resultado)))
44+
else:
45+
print("%s+%s=CONCORDIA CUM VERITATE" % (a,b))

‎DMOJ/cco10p6.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@
66
tamanho = 27
77
binario = [{}]
88
for i in alfabeto:
9-
binario[0][i] = i
10-
logartimos = range(32)
9+
binario[0][i] = i
10+
logartimos = list(range(32))
1111
for i in alfabeto:
12-
davez = raw_input()
13-
binario.append({})
14-
binario[1][i] = davez
15-
vez = int(raw_input())
16-
raiz = min(int(vez**0.5)+1,vez)
17-
for i in xrange(2,raiz+1):
18-
binario.append({})
19-
for j in alfabeto:
20-
binario[i][j] = binario[1][binario[i-1][j]]
12+
davez = input()
13+
binario.append({})
14+
binario[1][i] = davez
15+
vez = int(input())
16+
raiz = min(int(vez**0.5)+1, vez)
17+
for i in range(2,raiz+1):
18+
binario.append({})
19+
for j in alfabeto:
20+
binario[i][j] = binario[1][binario[i-1][j]]
2121
resto = vez % raiz
2222
quociente = vez - resto
2323
quociente /= raiz
2424
if resto != 0:
25-
resposta = binario[resto]
25+
resposta = binario[resto]
2626
elif resto == 0 and vez != 0:
27-
resposta = binario[raiz]
28-
for i in xrange(quociente):
29-
for j in alfabeto:
30-
resposta[j] = binario[raiz][resposta[j]]
31-
entrada = [resposta[i] for i in raw_input()]
32-
print"".join(entrada)
27+
resposta = binario[raiz]
28+
for i in range(quociente):
29+
for j in alfabeto:
30+
resposta[j] = binario[raiz][resposta[j]]
31+
entrada = [resposta[i] for i in input()]
32+
print("".join(entrada))

‎DMOJ/coci06c2p2.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Ivan Carvalho
22
# Solution to https://dmoj.ca/problem/coci06c2p2
3-
dicio = dict(zip(["A","B","C"],sorted([int(i) for i in
4-
input().split()])))
5-
lista = [str(dicio[i]) for i in input()]
6-
print(" ".join(lista))
3+
dicio = dict(list(zip(["A", "B", "C"], sorted([int(i) for i in input().split()]))))
4+
lista = [str(dicio[i]) for i in eval(input())]
5+
print((" ".join(lista)))

‎DMOJ/coci06c2p4.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Ivan Carvalho
22
# Solution to https://dmoj.ca/problem/coci06c2p4
33

4-
N = int(input())
4+
N = int(eval(input()))
55
ans = 0
66

7-
for i in range(1,N+1):
8-
for j in range(i+2,N+1):
9-
a = j - i - 1
10-
b = N - a - 2
11-
ans += a*b
7+
for i in range(1,N+1):
8+
for j in range(i+2, N+1):
9+
a = j - i - 1
10+
b = N - a - 2
11+
ans += a*b
1212

13-
print(ans//2)
13+
print((ans//2))

‎DMOJ/coci06c3p2.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
# Ivan Carvalho
22
# Solution to https://dmoj.ca/problem/coci06c3p2
33

4-
def abs_pares(a,b):
5-
return abs(a[0] - b[0]) + abs(a[1] - b[1])
4+
5+
def abs_pares(a, b):
6+
return abs(a[0] - b[0]) + abs(a[1] - b[1])
7+
68

79
dicio = {
8-
"A" : (0,0), "B" : (0,1), "C" : (0,2), "D" : (0,3),
9-
"E" : (1,0), "F" : (1,1), "G" : (1,2), "H" : (1,3),
10-
"I" : (2,0), "J" : (2,1), "K" : (2,2), "L" : (2,3),
11-
"M" : (3,0), "N" : (3,1), "O" : (3,2), "." : (3,3)
10+
"A": (0, 0),
11+
"B": (0, 1),
12+
"C": (0, 2),
13+
"D": (0, 3),
14+
"E": (1, 0),
15+
"F": (1, 1),
16+
"G": (1, 2),
17+
"H": (1, 3),
18+
"I": (2, 0),
19+
"J": (2, 1),
20+
"K": (2, 2),
21+
"L": (2, 3),
22+
"M": (3, 0),
23+
"N": (3, 1),
24+
"O": (3, 2),
25+
".": (3, 3),
1226
}
1327

1428
ans = 0
1529

1630
for i in range(4):
17-
entrada = input()
18-
for j,c in enumerate(entrada):
19-
if c == ".":
20-
continue
21-
ans += abs_pares((i,j), dicio[c])
31+
entrada = eval(input())
32+
for j,c in enumerate(entrada):
33+
if c == ".":
34+
continue
35+
ans += abs_pares((i,j), dicio[c])
2236

23-
print(ans)
37+
print(ans)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /