항해 3주차 프로그램 기초 주차 회고

성민·2023년 2월 4일
0

항해99

목록 보기
7/9

알고리즘에 대한 본격적인 시작을 하는 주차로 초급단계의 프로그래머스 문제 해결, 알고리즘 초급단계 시험

공부한 내용

1. 알고리즘 공부

1) 초급단계의 알고리즘 문제 풀기

  • 백준 문제) 1110, 2839, 1011, 4948, 1436, 2869, 1037, 2609, 10250, 1929, 11729, 11651, 2805, 10828, 10773, 9012, 1934, 11050
  • 프로그래머스) 0단계 문제

2) 재귀 공부

하나의 함수에서 자신을 다시 호출하여 작업을 수행하는 방식으로 주어진 문제를 푸는 방법

  • 하노이의 탑

public class Main {
    private static final StringBuilder output = new StringBuilder();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Main main = new Main();

        int n = sc.nextInt();
		
        //하노이의 탑 총 횟수 구하는 공식
        System.out.println((int)Math.pow(2, n) - 1);
        //하노이의 탑 구현
        main.hanoi(n, 1, 3, 2);
        System.out.println(output);
    }

    void hanoi(int number, int start, int to, int via) {
        if (number == 1) {
            move(number, start, to);
            return;
        }
        hanoi(number - 1, start, via, to);
        move(number, start, to);
        hanoi(number - 1, via, to, start);
    }

    void move(int number, int start , int to) {
        output.append(start + " " + to + "\n");
    }

}

2. 자바 공부

  1. String api
  • split(조건) - 문자열을 해당조건을 기준으로 나뉘는 배열로 만들어줌
  • carAt(index) - index의 값을 char로 리턴
  • replace(조건, 변경할내용) - 조건에 해당하는 부분을 변경할 내용으로 바꿈
  • substring(startIndex, endIndex) - startIndex에서 endIndex 이전까지 추출
  1. 상속
  • 상속받는 클래스를 자식 클래스 상속을 해주는 클래스를 부모 클래스라 지칭
  • 자식 클래스는 부모클래스의 변수와 함수를 사용가능하고 부모에서 생성된 메소드를 Override로 재선언이 가능
//부모 클래스
class Parent {
	String parentValue;
   
  	Parent(String parentValue) {
        this.parentValue = parentValue;
    }
    
    public int setValue() {
    	System.out.println(this.parentValue);
    }
}
//자식 클래스
class Child extends Parent {
	String childValue;
   
  	Parent(String parentValue, String childValue) {
    	// 부모 생성자호출
    	super(parentValue)
        this.childValue = childValue;
    }
    
    @Override
    public int setValue() {
    	//부모 메소드 호출
    	super.setValue();
    	System.out.println(this.childValue);
    }
}
  1. 인터페이스
  • 추상 메서드의 집합
  • 구현된 것이 전혀 없는 설계도

interface PlayingCard {
    public static final int SPADE = 4;
    final int DIAMOND = 3; // public static final int DIAMOND = 3;
    static int HEART = 2;  // public static final int HEART = 2;
    int CLOVER = 1;        // public static final int CLOVER = 1;public abstract String getCardNumber();
    String getCardKing(); // public abstract String getCardKing();
}

class Unit {}interface Fightable extends Movable, Attackable {}interface Movable {
    void move(int x, int y);
}interface Attackable {
    void attack(Unit u);
}class InterfaceTest implements Fightable {@Override
    public void move(int x, int y) {
           (구현)
    }@Override
    public void attack(Unit u) {
           (구현)
    }
}

3. 스프링 공부

  1. spring boot 구성 및 로컬 서버 실행

이번주차에 느낀점

일단 알고리즘 문제를 계속 풀었다. 항해에서 제공해준 문제는 전체적으로 난이도가 낮은 문제들이라 전체적으로 푸는것에 어려움을 느끼지는 않았다.

쉽다 생각해서 조금더 난도 있는 문제들을 접해봤는데 알고리즘 기법들에 대한 공부를 전혀 안한 상태에서 보니까 정말 풀이방법을 생각하기 쉽지 않았다.

0개의 댓글