Skip to content

[정렬] 예제 및 실전 문제 해결(이시현) #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Implementation/4-1_updown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#시간복잡도 O(n),2n이지만,,

n=int(input())
gps=[1,1]
lst=list(input()) #이동 위치 입력
num=len(lst)

for i in range(num):
if lst[i]=="R":
if gps[1]<5:
gps[1]+=1

elif lst[i]=="L":
if gps[1]>1:
gps[1]-=1

elif lst[i]=="U":
if gps[0]>1:
gps[0]-=1

elif lst[i]=="D":
if gps[0]<5:
gps[0]+=1

print(gps[0],gps[1])
35 changes: 35 additions & 0 deletions Implementation/4-2_how_many_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

n=int(input())
clock=[0 for i in range(6)]
cnt=0

for i in range(n+1):
if clock[1]<9:
clock[1]=i
else:
clock[0]=i//10
clock[1]=0
clock[3],clock[2]=0,0

for j in range(60):
if clock[3]<9:
clock[3]+=1
else:
clock[2]+=1
clock[3]=0
clock[4],clock[5]=0,0

for k in range(60):
if clock[5]<9:
clock[5]+=1
else:
clock[4]+=1
clock[5]=0
print(clock)
for l in range(0,6):
if clock[l]==3:
cnt+=1
break

print(cnt)

31 changes: 31 additions & 0 deletions Implementation/4-3_knight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

gps=list(input())
print(gps)
cnt=0

diff_x=abs(ord(gps[0])-ord('h'))
diff_y=abs(int(gps[1])-8)

if diff_x==0 or diff_x==7:
if diff_y==0 or diff_y==7:
cnt=2
elif diff_y==1 or diff_y==6:
cnt=3
else:
cnt=4
elif diff_x==1 or diff_x==6:
if diff_y==0 or diff_y==7:
cnt=3
elif diff_y==1 or diff_y==6:
cnt=4
else:
cnt=6
else:
if diff_y==0 or diff_y==7:
cnt=4
elif diff_y==1 or diff_y==6:
cnt=6
else:
cnt=8

print(cnt)
59 changes: 59 additions & 0 deletions Implementation/4-4_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

n,m=map(int,input().split())

a,b,d=map(int,input().split()) #좌표와 방향
character_gps=[a,b]
map_structure=[0 for i in range(n)]

for i in range(n):
map_structure[i]=list(map(int,input().split()))
print(map_structure)

#입력 끝 탐색 시작

cnt=1
stuck=0 #네 방향 다 탐색했는지 찾는 변수
while(1):
if d==0: #방향이 위쪽일 때
if character_gps[0]>0 and map_structure[character_gps[0]-1][character_gps[1]]==0:
character_gps[0]-=1
map_structure[character_gps[0]][character_gps[1]]=1 #이미 가본곳은 못가게 하는 장치
cnt+=1
stuck=0
else:
d+=1
stuck+=1


elif d==2: #방향이 아래일 때
if character_gps[0]<n-1 and map_structure[character_gps[0]+1][character_gps[1]]==0:
character_gps[0]+=1
map_structure[character_gps[0]][character_gps[1]]=1
cnt+=1
stuck=0
else:
d+=1
stuck+=1
elif d==1: #방향이 오른쪽일 때
if character_gps[1]<n-1 and map_structure[character_gps[0]][character_gps[1]+1]==0:
character_gps[1]+=1
map_structure[character_gps[0]][character_gps[1]]=1
cnt+=1
stuck=0
else:
d+=1
stuck+=1
elif d==3: #방향이 왼쪽일 때
if character_gps[1]>0 and map_structure[character_gps[0]][character_gps[1]-1]==0:
character_gps[0]-=1
map_structure[character_gps[0]][character_gps[1]]=1
cnt+=1
stuck=0
else:
d=0
stuck+=1

if stuck==4:
break

print(cnt)
9 changes: 9 additions & 0 deletions sort/6_2first.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
N=int(input())
lst=[]
for i in range(n):
lst[i]=int(input())

lst=sorted(lst,reversed=True)

for i in lst:
print(i,end=" ")
9 changes: 9 additions & 0 deletions sort/6_3first copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
N=int(input())
lst=[]
for i in range(n):
lst[i]=int(input())

lst=sorted(lst,reversed=True)

for i in lst:
print(i,end=" ")
14 changes: 14 additions & 0 deletions sort/6_4first copy 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
n,k=map(int,input().split())

a=list(map(int,input().split()))
b=list(map(int,input().split()))

a.sort() #배열 정렬
b.sort(reverse=True)

for i in range(k):
if a[i]<b[i]:
a[i],b[i]=b[i],a[i]
else:
break
print(sum(a))