본문 바로가기

Algorithm 💡/String12

[소프티어 7703번] X marks the Spot (한양대 HCPC 2023) Softeer - 현대자동차그룹 SW인재확보플랫폼 softeer.aiimport sys# 1. n개의 문자열쌍(S,T)이 주어지는데, 각 쌍에 대해서 S와 T의 길이는 같다# 2. S에서 글자 x 또는 X가 등장하는 위치를 P라고 한다.(유일)# 3. 이때 T의 P번째 글자를 읽는다.(소문자는 대문자로 변환)input = sys.stdin.readlineN = int(input())answer = []for _ in range(N): str1, str2 = input().split() str1_set, str2_set = set(str1), set(str2) x_index = -1 X_index = -1 if 'x' in str1_set: x_index = str1.. 2024. 6. 16.
[프로그래머스] JadenCase 문자열 만들기 def solution(s): words = s.split() blanks = [] for i,value in enumerate(s): if value == ' ': # 공백문자인 경우 if i == 0: # 첫번째 문자인 경우(index error 방지) blanks.append(' ') else: if s[i-1] == ' ': # 연속된 공백문자일 경우 blanks[-1] += ' ' else: blanks.append(' ') def convertWord(string): # JadenCase로 문자열 변환해주는 함수 result = '' for i,value in enumerate(string): if i == 0: if ord('a') 2024. 1. 5.
[백준 5052번] 전화번호 목록 5052번: 전화번호 목록 첫째 줄에 테스트 케이스의 개수 t가 주어진다. (1 ≤ t ≤ 50) 각 테스트 케이스의 첫째 줄에는 전화번호의 수 n이 주어진다. (1 ≤ n ≤ 10000) 다음 n개의 줄에는 목록에 포함되어 있는 전화번호가 www.acmicpc.net import sys input = sys.stdin.readline t = int(input().rstrip()) for _ in range(t): n = int(input().rstrip()) cases = [] flag = True for _ in range(n): cases.append(input().rstrip()) cases.sort() # for i in range(len(cases)): # if flag: # break # f.. 2023. 12. 13.
[프로그래머스] 옹알이(2) def solution(babbling): answer = 0 prefix_list = ['a','y','w','m'] global current current = '' def check(string): global current list_str = list(string) index = 0 while(index 2023. 7. 22.
[프로그래머스] 문자열 나누기 def solution(s): answer = [] string = s while(string != ''): x = string[0] list_str = list(string) count_x = 0 count_not_x = 0 index = 0 for i,value in enumerate(list_str): if value == x: count_x += 1 else: count_not_x += 1 if count_x != 0 and count_x == count_not_x: index = i break index = i answer.append(list_str[:index+1]) string = ''.join(list_str[index+1:]) return len(answer) 이번 문제는 주어진 조건대.. 2023. 7. 21.
[프로그래머스] 문자열 밀기 def solution(A, B): def move(string): list_str = list(string) str_len = len(list_str) new_list = [list_str[-1]] + list_str[:-1] print(new_list) return ''.join(new_list) available = False check_str = A answer = 0 for i in range(len(A)): if check_str == B: available = True break check_str = move(check_str) answer += 1 if available: return answer else: return -1 이번 문제는 주어진 문자열 A를 오른쪽으로 밀면서 B를 만들 수 .. 2023. 7. 21.