K

@kimjuha19

문자열 뒤집기

Python
6 months ago
word = "python" stack = [] result = "" for ch in word: stack.append(ch) for i in range(len(stack)): result += stack.pop(-1)

클래스 메서드(@classmethod)

Python
6 months ago
class Coffee: price = 3000 @classmethod def set_price(cls, new_price): cls.price = new_price coffee1 = Coffee() coffee2 = Coffee()

super()를 이용한 초기화

Python
6 months ago
class Person: def __init__(self, name): self.name = name class Student(Person): def __init__(self,name,major): self.major = major super().__init__(name) print(self.name,self.major)

여러 개의 인스턴스 상호작용

Python
6 months ago
class Warrior: def __init__(self, name): self.name = name self.hp = 100 def attack(self, target): target.hp -= 10 print(target.hp) mywarrior1 = Warrior("김")

매개변수가 있는 생성자 심화

Python
6 months ago
class Rectangle: def __init__(self, width, height): self.width = width self.height = height def area(self): print(self.width * self.height) def perimeter(self): print(2 * (self.width + self.height))

조건문을 포함한 메서드 설계

Python
6 months ago
class Bank: def __init__(self): self.balance = 1000 def withdraw(self, amount): self.balance -= amount if self.balance < 0: print("잔액 부족")

메서드를 통한 값의 변경

Python
6 months ago
class Smartphone: def __init__(self): self.battery_level = 100 def use(self, amount): self.battery_level -= amount if self.battery_level < 0: self.battery_level = 0 def charge(self, amount):

상속과 기능 확장(2)

Python
6 months ago
class Employee: count = 0 def __init__(self, name): self.name = name Employee.count += 1 def info(self): print(self.name,Employee.count) myname = Employee("Benjamin")

기본 클래스와 속성 설정(2)

Python
6 months ago
class Book: def __init__(self, title,author): self.title = title self.author = author def info(self): print(self.title,self.author) mybook = Book("python","class") mybook.info()

클래스 변수의 활용

Python
6 months ago
class Vehicle: def drive(self): print("자동차가 달립니다.") class ElectricCar(Vehicle): def drive(self): print("전기로 조용히 달립니다") mycar = ElectricCar() mycar.drive()

리스트 객체 관리

Python
6 months ago
class ShoppingCart: def __init__(self): self.items = [] def add_item(self, item_name): self.items.append(item_name) def show_items(self): print(self.items)

상속과 기능 확장

Python
6 months ago
class vehicle: def drive(self): print("자동차가 달립니다") def tire(self): print("금호타이어") class elecar(vehicle):

기본 클래스와 속성 설정

Python
6 months ago
class book: def __init__(self, title,author): self.title = title self.author = author def info(self): print(f"도서명: {self.title} 저자: {self.author}") mybook = book("top gun","tom") mybook.info()

회의 정렬

Python
6 months ago
n = int(input()) table = [] start = 0 end = 0 # [(길이, 시작, 번호)] # [(2, 3, 2), (1, 2, 4), (8, 7, 3)] for n in range(1, n+1): start, end = map(int, input().split())

또래 구하기

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