자료구조와 알고리즘/알고리즘
-
스택과 문제들 풀면서 얻은..자료구조와 알고리즘/알고리즘 2023. 4. 5. 14:07
스택과 관련 문제들을 풀어보았다. 문제를 풀면서 얻은 점들 한눈에 볼 수 있도록 정리하려고 작성했다. 스택은 LIFO구조. 저장된 데이터의 마지막 값이 의미있는 경우에 사용하면 편하다! -얻은점 >테스트케이스 주어질때는 바로 입출력하는 방식이 좋다. --단어 뒤집기 1,2 ★--- >문자열 다룰 때 자바 eof (입력,파일 스트림으로부터 모두 읽기) while((input=readLine()) !=null) while((input=read()) !=-1) while(scanner.hasNext()) > 문자열을 중심으로 입력을 받고 char[]로 변환해서 사용하는 것이 훨씬 편한듯하다. read() --쪼끔구리다 readLine() 개행무시 - char[] 다룰때 필요하다면 미리 추가해두자. > 스택에 ..
-
프코전-자바편 1~2장자료구조와 알고리즘/알고리즘 2023. 3. 30. 21:31
1장 -코드를 짤 때 흔히하는 실수 코드를 짤 때 가독성과 역할을 충분히 고려하지 못하고 쌓아올리기 시작하면, 어느순간 코드를 수정하는 것 보다 갈아 엎는 것이 나을 때가 생긴다. 이러한 상황을 방지하기 위해서 코드를 작성할 때 가독성과 역할을 신경 쓰며 문제를 단계별로 나누어 해결해보자 -디버깅과 시행착오 줄이기 > 코드를 단계별로 작성하라 > 하나의 단계를 작성하고 검증하라 > 단계 검증이 실패하면, 실패한 단계에서 더 자세히 로그를 찍어보자 - 실습 -전화번호부 만들기 사용자가 입력한 전화번호를 가진 사람들을 전화번호부에서 검색하는 기능을 구현해보자 처음에는 입력과 검색 모든 과정을 한 번에 생각하면서 코드를 작성하려 할 것이다. 이는 가독성이 떨어지는 코드 작성의 시발점이다. 전화번호를 검색하는 ..