-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
n=int(input()) | ||
m=int(input()) | ||
if m == 0: | ||
blocks=[] | ||
else: | ||
blocks = list(map(int, input().split())) | ||
mimimum = abs(100-n) | ||
for i in range(99999): | ||
num = str(i) | ||
for j in num: | ||
if int(j) in blocks: #포함되어 있으면 | ||
break | ||
else: | ||
minimum = min(mimimum, abs(n-i)+len(num)) | ||
print(minimum) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sys | ||
|
||
|
||
for i in range(N): | ||
result |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
n = int(input()) | ||
d = [0]*(10**6+1) | ||
for i in range(2, n+1): | ||
d[i] = d[i-1]+1 | ||
if i%3 == 0: | ||
d[i] = min(d[i], d[i//3]+1) | ||
if i%2 == 0: | ||
d[i] = min(d[i], d[i//2]+1) | ||
print(d[n]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
exp = input().split("-") | ||
num =[] | ||
for i in exp: | ||
sum = 0 | ||
tmp = i.split("+") | ||
for j in tmp: | ||
sum+=int(j) | ||
num.append(sum) | ||
n = num[0] | ||
for i in range(1, len(num)): | ||
n-=num[i] | ||
print(n) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
equa = list(map(str, input().split("-"))) | ||
total = 0 | ||
for i, val in enumerate(equa): | ||
temp_list = list(map(int, val.split("+"))) | ||
if i == 0: | ||
total += sum(temp_list) | ||
continue | ||
total -=sum(temp_list) | ||
print(total) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
equa = list(map(str, input().split("-"))) | ||
total = 0 | ||
for i, val in enumerate(equa): | ||
temp_list = list(map(int, val.split("+"))) | ||
if i == 0: | ||
total+=sum(temp_list) | ||
continue | ||
total -=sum(temp_list) | ||
print(total) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
equa = list(map(str, input().split("-"))) | ||
total = 0 | ||
for i, val in enumerate(equa): | ||
temp_list = list(map(int, val.split("+"))) | ||
if i == 0: | ||
total+=sum(temp_list) | ||
continue | ||
total -=sum(temp_list) | ||
print(total) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
equa = list(map(str, input().split("-"))) | ||
total = 0 | ||
for i, val in enumerate(equa): | ||
temp_list = list(map(int, val.split("+"))) | ||
if i == 0: | ||
total+=sum(temp_list) | ||
continue | ||
else: | ||
total-=sum(temp_list) | ||
print(total) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
nums = input() | ||
current_number = "" | ||
result = 0 | ||
sign = 1 | ||
for i in nums: | ||
if i.isdigit(): | ||
current_number+=i | ||
else: | ||
result+= sign * int(current_number) | ||
if i == "-": | ||
sign = -1 | ||
current_number = "" | ||
result+= sign * int(current_number) | ||
print(result) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def main(): | ||
n, m = map(int, input().split()) | ||
name_to_number = {} | ||
number_to_name = {} | ||
|
||
for i in range(1, n + 1): | ||
name = input() | ||
name_to_number[name] = i | ||
number_to_name[i] = name | ||
|
||
for _ in range(m): | ||
query = input() | ||
if query.isdigit(): | ||
print(number_to_name[int(query)]) | ||
else: | ||
print(name_to_number[query]) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
n,m = map(int, input().split()) | ||
dict = {} | ||
|
||
for i in range(1,n+1): | ||
a = input().rstrip() | ||
dict[i] = a | ||
dict[a] = i | ||
for i in range(m): | ||
query = input().rstrip() | ||
if query.isdigit(): | ||
print(dict[int(query)]) | ||
else: | ||
print(dict[query]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from collections import deque | ||
def bfs(): | ||
q = deque() | ||
q.append(n) | ||
while q: | ||
x = q.popleft() | ||
if x == k: | ||
print(dist[x]) | ||
break | ||
for nx in (x-1, x+1, x*2): | ||
if 0<=nx<=MAX and not dist[nx]: | ||
dist[nx] = dist[x]+1 | ||
q.append(nx) | ||
|
||
|
||
|
||
MAX = int(10**5) | ||
dist = [0]*(MAX+1) | ||
n,k = map(int, input().split()) | ||
|
||
bfs() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from collections import deque | ||
def bfs(): | ||
q=deque() | ||
q.append(n) | ||
while q: | ||
x = q.popleft() | ||
if x == k: | ||
print(dist[x]) | ||
break | ||
for nx in (x-1, x+1, x*2): | ||
if 0<=nx<=MAX and not dist[nx]: | ||
dist[nx] = dist[x]+1 | ||
q.append(nx) | ||
|
||
MAX = 10**5 | ||
dist = [0]*(MAX+1) | ||
n,k = map(int, input().split()) | ||
bfs() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from collections import deque | ||
def bfs(): | ||
q=deque() | ||
q.append(n) | ||
while q: | ||
x=q.popleft() | ||
if x == k: | ||
print(dist[x]) | ||
break | ||
for nx in (x-1, x+1, x*2): | ||
if 0<=nx<=MAX and not dist[nx]: | ||
dist[nx] = dist[x]+1 | ||
q.append(nx) | ||
MAX = 10**5 | ||
dist = [0]*(MAX+1) | ||
n,k = map(int, input().split()) | ||
|
||
bfs() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
n,m = map(int, input().split()) | ||
unheard = set() | ||
unseen = set() | ||
for _ in range(n): | ||
unheard.add(input()) | ||
for _ in range(m): | ||
unseen.add(input()) | ||
intersection = sorted(list(unheard & unseen)) | ||
print(len(intersection)) | ||
for i in intersection: | ||
print(i) |