분류 전체보기(178)
-
11365 !밀비 급일 - Swift
1. 풀이 코드while true { if let message = readLine() { if message == "END" { break } let reversedMessage = String(message.reversed()) print(reversedMessage) }} Swift는 let이 상수 선언에 사용되고, var이 변수 선언에 사용되는군요. String(message.reversed()) 로 뒤집어서 string 형태로 바꾸는 것도 신기합니다.백준: https://www.acmicpc.net/problem/11365
2024.07.30 -
11365 !밀비 급일 - C
1. 풀이 코드#include #include int main() { char message[500]; while(1){ scanf(" %[^\n]", message); if(strcmp(message, "END") == 0){ break; } for (int i = strlen(message) - 1; i >= 0; i--){ printf("%c", message[i]); } printf("\n"); } return 0;} scanf(" %[^\n]", message);는 공백을 포함한 문자열을 입력받기 위해 사용됩니다. 앞의 공백은 이전 입력의 남은 개행 문자를 무..
2024.07.29 -
둘만의 암호 - Python
1. 풀이 코드 def solution(s, skip, index): alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] secret_alphabet = [] skip_alphabet = [] for item in skip: skip_alphabet.append(item) for item in alphabet: if item not in skip_alphabet: secret_alphabet.append(item) answer = '' for item in s: answer += secret_alphabe..
2024.01.31 -
완주하지 못한 선수 - Python
1. 풀이 코드 def solution(participant, completion): list1 = sorted(participant) list2 = sorted(completion) for i, item in enumerate(list1): if i < len(list2) and list1[i] != list2[i]: return item elif i == len(list2): return item return -1 위와 같이 풀었습니다. 2. 다른 사람 풀이 코드 def solution(participant, completion): participant.sort() completion.sort() for i in range(len(completion)): if participant[i] != comp..
2024.01.29 -
대충 만든 자판 - Python
1. 풀이 코드 def search_char(string, target_char): for index, item in enumerate(string): if item == target_char: return index + 1 return 0 def solution(keymap, targets): answer = [] for item in targets: add_index = 0 for target_char in item: index = 101 for check_list in keymap: temp_index = search_char(check_list, target_char) if temp_index != 0: index = min(index, temp_index) add_index += index if..
2024.01.28 -
문자열 나누기 - Python
1. 풀이 코드 def solution(s): answer = 0 count1 = 0 count2 = 0 char1 = '' for item in s: if char1 == '': char1 = item count1 = 1 else: if char1 == item: count1 += 1 else: count2 += 1 if count1 == count2: answer += 1 count1 = 0 count2 = 0 char1 = '' if char1 != '': answer += 1 return answer 직관적으로 짰습니다. 2. 다른 사람 풀이 코드 def solution(s): answer = 0 sav1=0 sav2=0 for i in s: if sav1==sav2: answer+=1 a=i i..
2024.01.27 -
숫자 짝꿍 - Python
1. 풀이 코드 def solution(X, Y): X_list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] Y_list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for i in range(0, 10): X_list[i] = X.count(str(i)) Y_list[i] = Y.count(str(i)) answer = '' for i in range(9, -1, -1): if i != 0 or len(answer) != 0: while X_list[i] != 0 and Y_list[i] != 0: answer += f"{i}" X_list[i] -= 1 Y_list[i] -= 1 elif i == 0 and (X_list[i] != 0 and Y_list[i] != 0):..
2024.01.25