-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
ca62fd3
commit f246bbe
Showing
5 changed files
with
190 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,25 @@ | ||
import sys; input=sys.stdin.readline | ||
from collections import defaultdict | ||
|
||
# 함수 구현 | ||
def dfs(arr, visited, num): | ||
global answer | ||
visited[num] = 1 | ||
for a in arr[num]: | ||
if not visited[a]: | ||
answer += 1 | ||
dfs(arr, visited, a) | ||
|
||
# 변수 설정 | ||
computer_cnt = int(input()) | ||
linked_cnt = int(input()) | ||
arr_dict = defaultdict(list) | ||
for a in [list(map(int, input().split())) for _ in range(linked_cnt)]: | ||
arr_dict[a[0]].append(a[1]) | ||
arr_dict[a[1]].append(a[0]) | ||
visited = [0]*(computer_cnt+1) | ||
answer = 0 | ||
|
||
# dfs 실행 | ||
dfs(arr_dict, visited, 1) | ||
print(answer) |
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 @@ | ||
def solution(table, languages, preference): | ||
answer = [] | ||
for t in table: | ||
num = 6 | ||
table_list = t.split() | ||
sum = 0 | ||
for tl in table_list: | ||
for lp, val in list(zip(languages,preference)): | ||
if tl == lp: | ||
sum += (int(val)*int(num)) | ||
num -= 1 | ||
answer.append(sum) | ||
index = list(filter(lambda x: answer[x] == max(answer), range(len(answer)))) | ||
final_answer = [] | ||
for i in index: | ||
final_answer.append(table[i].split()[0]) | ||
return sorted(final_answer)[0] | ||
|
||
if __name__ == '__main__': | ||
print(solution(["SI JAVA JAVASCRIPT SQL PYTHON C#", "CONTENTS JAVASCRIPT JAVA PYTHON SQL C++", "HARDWARE C C++ PYTHON JAVA JAVASCRIPT", "PORTAL JAVA JAVASCRIPT PYTHON KOTLIN PHP", "GAME C++ C# JAVASCRIPT C JAVA"], ["PYTHON", "C++", "SQL"], [7, 5, 5])) | ||
# print(solution( ["SI JAVA JAVASCRIPT SQL PYTHON C#", "CONTENTS JAVASCRIPT JAVA PYTHON SQL C++", "HARDWARE C C++ PYTHON JAVA JAVASCRIPT", "PORTAL JAVA JAVASCRIPT PYTHON KOTLIN PHP", "GAME C++ C# JAVASCRIPT C JAVA"], ["JAVA", "JAVASCRIPT"], [7, 5])) |
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,36 @@ | ||
import re | ||
from itertools import groupby | ||
|
||
def solution(inp_str): | ||
flag = True | ||
answer = [] | ||
# 1번 조건 | ||
if not (8<=len(inp_str)<=15): | ||
flag = False | ||
answer.append(1) | ||
# 2번 조건 | ||
if not (inp_str == ''.join(re.findall('[a-zA-Z0-9가-힣~!@#$%^&*]', inp_str))): | ||
flag = False | ||
answer.append(2) | ||
# 3번 조건 | ||
valid=0 | ||
if re.search('[0-9]', inp_str) is not None: valid += 1 | ||
if re.search('[a-z]', inp_str) is not None: valid += 1 | ||
if re.search('[A-Z]', inp_str) is not None: valid += 1 | ||
if re.search('[~!@#$%^&*]', inp_str) is not None: valid += 1 | ||
if valid < 3: | ||
flag = False | ||
answer.append(3) | ||
# 4번 조건 | ||
if max([len(list(g)) for k,g in groupby(inp_str)], default=0) >= 4: | ||
answer.append(4) | ||
# 5번 조건 | ||
for inp in inp_str: | ||
if inp_str.count(inp) >= 5: | ||
flag = False | ||
answer.append(5) | ||
|
||
if flag: | ||
answer.append(0) | ||
|
||
return sorted(set(answer)) |
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,6 @@ | ||
def solution(enter, leave): | ||
answer = [] | ||
return answer | ||
|
||
if __name__ == '__main__': | ||
print(solution([1,3,2], [1,2,3])) |
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,102 @@ | ||
import math | ||
|
||
# 적절한 명령어가 들어갔는지 테스트하는 함수 | ||
def program_commandCheck(program, flag_rules, command): | ||
# flag_rule_manufactor 함수에 flag_rules를 넣어 보기 좋게 나온 dict 값을 꺼낸다. | ||
flag_rule_dict = flag_rule_manufactor(flag_rules) | ||
print('flag_rule_dict : ', flag_rule_dict) | ||
# 하나의 명령에 대해서 공백을 기준으로 list에 넣는다. | ||
command_list = command.split() | ||
# 가장 앞에 값은 program이랑 비교를 해야하기 때문에 pop으로 꺼내서 비교 | ||
# program값과 다르다면 False 리턴 | ||
if command_list.pop(0)!=program: | ||
return False | ||
# flag와 flag_argument_type을 확인하여 알맞은 값이 들어갔는지 확인 | ||
# NULL인 경우를 제외하고는 2개씩 짝을 이루기 때문에 4개의 값이 들어있으면 2번, 5개의 값이 들어있으면 3번 반복문을 돌린다. | ||
# python의 경우 0.5를 반올림 하면 0이 나오기 때문에 0.1을 더한 뒤 반올림 해주었다. | ||
for _ in range(round(len(command_list)/2+0.1)): | ||
comm = command_list.pop(0) | ||
# 만약 처음으로 꺼낸 값에 - 가 들어있지 않다면 올바른 형식이 아니므로 False리턴 | ||
if not comm.count('-'): | ||
return False | ||
# flag_rule_dict에서 key값을 comm으로 두고 하나하나 확인한다. | ||
comm_type = flag_rule_dict[comm] | ||
# STRING인데 문자가 아닐 경우 False | ||
if comm_type == 'STRING': | ||
if command_list: | ||
if not(command_list.pop(0).isalpha()): | ||
return False | ||
else: | ||
return False | ||
|
||
# STRINGS인데 문자가 아닐 경우 False | ||
if comm_type == 'STRINGS': | ||
if command_list: | ||
while command_list[0].count('-')==0: | ||
if not(command_list.pop(0).isalpha()): | ||
return False | ||
else: | ||
return False | ||
|
||
# NUMBER인데 숫자가 아닐 경우 False | ||
elif comm_type == 'NUMBER': | ||
if command_list: | ||
if not(command_list.pop(0).isdigit()): | ||
return False | ||
else: | ||
return False | ||
|
||
# NUMBERS인데 숫자가 아닐 경우 False | ||
elif comm_type == 'NUMBERS': | ||
if command_list: | ||
while command_list[0].count('-')==0: | ||
if not(command_list.pop(0).isdigit()): | ||
return False | ||
else: | ||
return False | ||
|
||
# NULL이고 다음에 문자가 남아있을경우, 그 문자가 -를 포함하고 있지 않으면 argument가 들어갔단 소리니 False | ||
elif comm_type == 'NULL': | ||
if command_list: | ||
if command_list[0].count('-')>0: | ||
return False | ||
# 이외에는 True 리턴 | ||
return True | ||
|
||
# flag_rules를 보기 좋게 dict에 넣는 함수 | ||
# -n ALIAS -num | ||
def flag_rule_manufactor(flag_rules): | ||
flag_rule_dict = dict() | ||
|
||
for fr in flag_rules: | ||
temp = [] | ||
val = fr.split() | ||
if 'ALIAS' in val: | ||
temp.append(val[0]) | ||
temp.append(val[2]) | ||
else: | ||
flag_name, flag_argument_type = val | ||
flag_rule_dict[flag_name]=flag_argument_type | ||
if temp: | ||
global value | ||
value = '' | ||
for t in temp: | ||
|
||
if t in flag_rule_dict.keys(): | ||
value = flag_rule_dict[t] | ||
print('value', value) | ||
for t in temp: | ||
flag_rule_dict[t]=value | ||
return flag_rule_dict | ||
|
||
# 메인 함수 | ||
def solution(program, flag_rules, commands): | ||
answer = [] | ||
# 한 개의 명령 씩 꺼내서 나온 결과를 answer 에 append | ||
for command in commands: | ||
result = program_commandCheck(program, flag_rules, command) | ||
answer.append(result) | ||
return answer | ||
|
||
if __name__ == '__main__': | ||
print(solution("bank", ["-send STRING", "-a ALIAS -amount", "-amount NUMBERS"], ["bank -send abc -amount 500 200 -a 400", "bank -send abc -a hey"])) |