K

@kimjuha19

또래 구하기

Python
6 months ago
arr = [60,2,19,39,100,50,89] arr.sort() temp = [] answer = arr[1] - arr[0] for i in range(len(arr)-1): ans = arr[i+1] - arr[i] temp.append(ans)

최대·최소 제거 평균

C
6 months ago
#include <stdio.h> int main() { int N; scanf("%d", &N); int score, sum = 0; int max = -100, min = 100; for (int i = 0; i < N; i++) {

누적 합 배열

C
6 months ago
#include <stdio.h> int main() { int A[10] = {3,7,1,-4,10,71,5,11,20,-5}; int P[10]; int i; P[0] = A[0]; for (i = 1; i < 10; i++) { P[i] = P[i-1] + A[i];

괄호 문자열 검사

C
6 months ago
#include <stdio.h> int main() { char str[] = "(()()))()"; int count = 0; int i; for (i = 0; str[i] != '\0'; i++) { if (str[i] == '(') { count++;

두 수의 합이 0이 되는 모든 쌍

Python
6 months ago
arr = [5, 0, 1, -2, 7, -3, 12, -10, 2, 10] answer = 0 for i in range(len(arr)): for j in range(i+1,len(arr)): if arr[i] + arr[j] == 0: answer += 1 print(answer)

증감증 수열 판단

Python
6 months ago
arr = [-2, -5, 7, 11, 0, -1, 3, 1, 5, 9] answer = 0 for i in range(0, len(arr) - 3): if arr[i] < arr[i+1] and arr[i+1] > arr[i+2] and arr[i+2] < arr[i+3]: answer += 1 break else: answer = 0

괄호 + 문자 검증

Python
6 months ago
s = input() count = 0 for ch in s: if ch == ('(','{','['): count += 1 else: count -= 1

괄호 확인

Python
6 months ago
s = input() count = 0 for ch in s: if ch == '(': count += 1 else: count -= 1

두 배열 교집합

Python
6 months ago
a = [1,2,3,4,5] b = [4,5,6,7,8] result = [] for i in a: if i not in b: result.append(i) for i in b: if i not in a:

문자열 압축

Python
6 months ago
lst = "aaabbc" 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
6 months ago
lst = "aaabbc" 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
6 months ago
a = list("abcde") b = list("cdeab") for i in range(len(a)): a = a[1:] + a[:1] if a == b: print("True") break else: print("False")

회전 배열 최소값

Python
6 months ago
lst = [4,5,6,1,2,3] k = lst[0] for i in range(1,len(lst)): listt= lst[k:] + lst[:k] if lst[i] < k: k = lst[i] print(k)

가장 긴 증가 부분

Python
6 months ago
arr = [1, 2, 2, 3, 4, 1] count = 0 maxcount = 1 for i in range(1,len(arr)): if arr[i] > arr[i-1]: count += 1 maxcount = max(maxcount,count) else: count = 1

숫자 삼각형

C
6 months ago
#include <stdio.h> int main() { int a; int b = 1; int n = 1; scanf("%d",&a);

대각선 합

C
6 months ago
#include <stdio.h> int main() { int arr[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; int n = 3;

회문(팰린드롬) 판별

Python
6 months ago
s = "Never odd or even" s = s.replace(" ", "").lower() if s == s[::-1]: print("True") else: print("False")

좌표 이동 시뮬레이션

Python
6 months ago
commands = "UURDL" x = 0 y = 0 for i in commands: if i == "U": y += 1 elif i == "D": y -= 1

특정 문자 개수 세기

Python
6 months ago
s = "AppleBanana" c = "a" count = 0 for ch in s: if ch.lower() == c.lower(): count += 1 print(count)

연속된 1의 최대 길이

Python
6 months ago
arr = [1, 1, 0, 1, 1, 1, 0, 1] max_cnt = 0 cnt = 1 for i in range(len(arr) - 1): if arr[i] == 1 and arr[i + 1] == 1: cnt += 1 else: cnt = 1