K

@kimjuha19

압축 문자열 길이 구하기

Python
7 months ago
lst = "aaabbcddd" ans = "" c = 1; for n in range(1,len(lst)): if lst[n] == lst[n-1]: c += 1 else: ans += lst[n-1]+str(c) c = 1

두 리스트의 공통 원소 개수

Python
7 months ago
A = [1,2,3,4,4] B = [3,4,5] set1 = set(A) set2 = set(B) common_elements = set1.intersection(set2) count = len(common_elements)

팰린드롬 판단하기(완)

Python
7 months ago
import string s = input() s = s.lower() s = ''.join(ch for ch in s if ch.isalnum()) if s == s[::-1]: print("True") else: print("False")

팰린드롬 판단하기

Python
7 months ago
num = input().split() for n in num: s = str(n) if s == s[::-1]: print("Ture") else: print("False")

영어 대상자 수 구하기

Python
7 months ago
scores = [650,722,914,558,714,803,650,679,669,800] count = 0 for s in scores: if 650 <= s and s < 800: count += 1 print(count)

369 박수 횟수

Python
7 months ago
n = int(input()) count = 0 for i in range(1, n + 1): s = str(i) for x in s: if x == '3' or x == '6' or x == '9': count += 1

빈도 기반 정렬

Python
7 months ago
arr = [4,4,1,2,2,3,3,3] result = sorted(arr, key=lambda x: (arr.count(x), x)) print(result)

리스트 뒤집기

Python
7 months ago
lst = [1, 4, 2, 3] for i in range(len(lst) // 2): result = len(lst) - i - 1 temp = lst[i] lst[i] = lst[result] lst[result] = temp print(lst)

등장하는 가장 많은 수와 가장 적은 수 구하기

Python
7 months ago
nums = [1,2,3,3,1,3,3,2,3,2] counts = {} for n in nums: if n in counts: counts[n] += 1 else: counts[n] = 1 print(counts)

리스트 합치기

Python
7 months ago
list1 = [1, 3, 5] list2 = [2, 4, 6] addlist = list1 + list2 n = len(addlist) for i in range(n - 1): minindex = i for j in range(i + 1, n): if addlist[j] < addlist[minindex]: minindex = j

절대값 기준 정렬

Python
7 months ago
numbers = [-1, 5, 3, -4, 100, 6] sorted_by_abs = sorted(numbers, key=abs) print(sorted_by_abs)

리스트 뒤집기

Python
7 months ago
lst = [1, 2, 3, 4, 5] for i in range(len(lst) // 2): result = len(lst) - i - 1 temp = lst[i] lst[i] = lst[result] lst[result] = temp print(lst)

선택정렬 스왑 횟수 구하기

Python
7 months ago
arr = [4, 1, 6, 3] count = 0 n = len(arr) for i in range(n - 1): minindex = i for j in range(i + 1, n): if arr[j] < arr[minindex]: minindex = j if minindex != i:

버블정렬 1회전 결과

C
7 months ago
#include <stdio.h> #define COUNT 4 int main() { int data[COUNT] = {4,3,1,2}; int temp = 0;

버블정렬 내림차순

C
7 months ago
#include <stdio.h> #define COUNT 5 int main() { int data[COUNT] = {5,1,4,3,2}; int temp = 0;

선택 정렬 구현

C
7 months ago
#include <stdio.h> int main(void) { int N; scanf("%d", &N); int arr[1000]; for (int i = 0; i < N; i++) { scanf("%d", &arr[i]); }

선택정렬 기본 원리

C
7 months ago
#include <stdio.h> int main(void) { int arr[5] = {5,2,9,1,7}; int minIndex = 0; for (int j = 1; j < 5; j++) { if (arr[j] < arr[minIndex]) { minIndex = j;

산 모양 배열 만들기

Python
7 months ago
n = int(input()) for i in range(1,n): print(i) for i in range(5,0,-1): print(i)

전자시계 패턴 변환

Python
7 months ago
led = { '0': 6, '1' : 2, '2' :5, '3' : 5, '4' : 4, '5' : 5, '6' : 6, '7' : 3, '8': 7, '9' : 6 } time = input() total = 0 for i in time: if i in led:

가장 많이 등장한 단어

Python
7 months ago
def mostcommonword(text): wordcounts = {} words = text.lower().split() for word in words: wordcounts[word] = wordcounts.get(word, 0) + 1 sortedwords = sorted(wordcounts.items(), key=lambda x: (-x[1], x[0])) return sorte