Skip to content

초급반 / 황재희 / 단어뒤집기2-17413, 파일정리-20291, ZOAC3-20436 #106

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 4 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
23 changes: 23 additions & 0 deletions week7/implementation/단어뒤집기2/hwangjaehee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
S = sys.stdin.readline().strip() + ' ' # 마지막에 공백 더하기
stack = []
result = ''
cnt = 0 # 괄호 안에 있는지 여부
for i in S :
if i == '<' : # <를 만나면
cnt = 1 # 지금 괄호 안에 있음 표시
for _ in range(len(stack)): #괄호 만나기 이전 stack 비우고 다 뒤집어서 더하기
result += stack.pop()
stack.append(i)

if i == '>' : # >를 만나면
cnt = 0 # 지금 괄호 빠져 나왔음 표시
for _ in range(len(stack)): # 괄호 안에 있는 애들은 뒤집지 않고 더하기
result += stack.pop(0)

if i == ' ' and cnt == 0: # 공백을 만나고 괄호 밖에 있다면
stack.pop() # 공백 빼기
for _ in range(len(stack)): # 뒤집어서 더하기
result += stack.pop()
result += ' '
print(result)
11 changes: 11 additions & 0 deletions week7/implementation/파일정리/hwangjaehee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
N = int(input())
dic = {} # 확장자를 담아줄 딕셔너리
for i in range(N):
_, extend = input().split('.') # .기준으로 문자열 분리
if extend in dic: # 딕셔너리에 확장자가 있다면 개수를 추가
dic[extend] += 1
else: # 없다면 새로 등록
dic[extend] = 1

for key in sorted(dic.keys()): # 딕셔너리의 key를 오름차순 정렬
print(key, dic[key])
48 changes: 48 additions & 0 deletions week7/simulation/ZOAC3/hwangjaehee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from sys import stdin

l, r = map(str, stdin.readline().rstrip().split()) # 왼손과 오른손 검지손가락의 초기 위치 문자 읽기
string = stdin.readline().rstrip() #입력해야 할 문자열을 읽기

keyboard = ['qwertyuiop', 'asdfghjkl', 'zxcvbnm']
mo = 'yuiophjklbnm' #모음 리스트
xl, yl, xr, yr = None, None, None, None #왼손좌표행렬, 오른손 좌표 행렬(초기화)

# 키보드 배열을 순회하며 왼손과 오른손 검지손가락의 초기 위치 문자에 해당하는 좌표 찾기기
for i in range(len(keyboard)):
# 현재 행 keyboard[i]에 왼손 초기 위치 문자 l이 있는지 확인
if l in keyboard[i]: # 있다면 해당 행 i와 해당 문자의 열 인덱스를 찾아 xl, yl에 저장합니다.
xl, yl = i, keyboard[i].index(l)

# 오른손 초기 위치 문자 r이 있는지 확인
if r in keyboard[i]: # 있다면 해당 행 i와 해당 문자의 열 인덱스를 찾아 xr, yr에 저장
xr, yr = i, keyboard[i].index(r)

ans = 0 # 총 걸린 시간을 저장할 변수를 초기화
for s in string:
ans += 1 # 각 문자를 누르는 데 기본적으로 1만큼의 시간이 소요

#오른손으로 눌러야 하는 경우(모음)
if s in mo:
for i in range(len(keyboard)):
if s in keyboard[i]: # 문있다면 해당 행 i와 해당 문자의 열 인덱스를 nx, ny에 저장
nx = i
ny = keyboard[i].index(s)
# 맨해튼 거리 = |행 차이| + |열 차이|
ans += abs(xr - nx) + abs(yr - ny)

xr, yr = nx, ny
break # 문자를 찾았으므로 내부 루프는 중단하고 다음 문자로 넘어가기기

#왼손으로 눌러야 하는 경우
else:
for i in range(len(keyboard)):
if s in keyboard[i]:
nx = i
ny = keyboard[i].index(s)

ans += abs(xl - nx) + abs(yl - ny)

xl, yl = nx, ny
break

print(ans)