전체 글
-
2차원 리스트 초기화 시 주의할 점Python 2020. 10. 12. 17:06
n x n 2차원 리스트를 0으로 초기화 시켜보고자 합니다. 파이썬의 리스트 관련 문법을 살펴보다 보면 아래와 같이 초기화 할 수 있을 것으로 생각합니다. n = 4 two_dimensional_list = [[0] * n] * n for e in two_dimensional_list: print(e) 위의 코드를 실행해보면 다음 그림과 같이 정상적으로 초기화 된 것으로 보입니다. 하지만 리스트 요소 값 중 하나를 다른 값으로 업데이트 해보도록 하겠습니다. n = 4 two_dimensional_list = [[0] * n] * n for e in two_dimensional_list: print(e) print("=============") two_dimensional_list[0][0] = 1 for..
-
콘솔 입력Java 2020. 10. 8. 11:35
1. Input stream에서 line을 읽어온다. 2. 특정 문자열로 split해서 그 결과를 String[] 타입 변수에 저장한다. import java.io.BufferedReader; import java.io.InputStreamReader; public class Application { public static void main(String[] args) throws Exception { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); String input = bufferedReader.readLine(); String[] strArray = input.split(" "); } }
-
console 입출력과 형변환Python 2020. 10. 8. 09:28
[Console 입력] 1. 공백없는 한 단어만 입력받기 var1 = input() 2. 공백을 기준으로 구분된 여러 단어들 입력받기 # input으로 받은 문자열을 split에 명시된 문자로 구별 # map을 사용하여 int형으로 변환 # list로 받아서 변수에 대입 var2, var3 = list(map(int, input().split())) 3. 보다 빠른 입력 함수 sys.stdin.readline()를 사용하기 import sys inputData = sys.stdin.readline().rstrip() # ① inputNumbers = list(map(int, inputData.split())) # ② print(inputNumbers) ① 표준 입력에서 readline()으로 입력된 문자..
-
그래프의 탐색 DFS, BFSData Structure & Algorithm 2020. 10. 6. 08:20
그래프의 모든 노드를 탐색하는 방법으로 DFS(Depth First Search:깊이 우선 탐색)와 BFS(Breadth First Search:너비 우선 탐색)가 있다. DFS는 stack을 BFS는 queue를 사용하여 각각 구현한다. (stack과 queue에 대해서는 다른 글을 참고) 그래프의 노드를 탐색하기 위해서는 노드간 간선에 의해 연결된 인접한 노드 정보가 필요하며 이 정보들을 행렬(2차원 리스트) 또는 리스트 형태로 저장하여 사용한다. 행렬 형태의 인접 노드 정보를 adjacency matrix라 하고 리스트 형태의 인접 노드 정보를 adjacency list라고 한다. adjacency matrix는 불필요한 정보까지 저장하게 되어 메모리를 낭비하게 되지만 원하는 관계 정보를 빠르게 조..
-
Stack과 QueueData Structure & Algorithm 2020. 9. 28. 19:31
stack과 queue를 java와 python으로 구현해보자. [Stack] stack은 LIFO(Last In First Out)로 동작하는 자료구조다. 일반적으로 함수 호출 시 스택구조를 사용한다. 따라서 스택을 사용해야 하는 알고리즘은 함수의 재귀호출로 대체할 수도 있다. stack with java import java.util.EmptyStackException; public class Stack_New { public static class Node { private final T data; private Node next; public Node(T data) { this.data = data; } public T getData() { return this.data; } public Node..
-
class 사용하기Python 2020. 9. 28. 11:00
class와 메서드 선언 class 클래스이름: #객체를 통해 사용할 수 있는 메서드 def 메서드이름1(self): 실행코드 #클래스를 통해 사용할 수 있는 메서드 @staticmethod def 메서드이름2(매개변수1, 매개변수2 ...): 실행코드 #만약 내용없는 class를 선언하고자 한다면 다른 내용 대신 pass를 입력 class의 속성 추가 # class 선언 시 속성 추가 class 클래스이름: 속성이름8 = 값# 클래스 속성. 이 클래스로 만들어진 모든 객체가 공유하는 속성이다. __속성이름9 = 값# __으로 시작하는 속성명은 java의 private 속성과 같다. __slot__=['속성이름5', '속성이름6'] """ 객체를 생성할 때 자동으로 호출되는 __init__ 메서드는 Ja..
-
vim 커스터마이징ETC 2020. 9. 21. 11:56
vim이 강력한 편집 도구라고 하는데 아직까지 체감이 많이 되지는 않는다. (얼마 써보지 않았으니깐) 처음 실행해보면 일반모드로 시작하기 때문에 입력도 안되고 여러모로 난감하다. 그래도 서버에서 바로 작업하고 배포하는데 이만한 게 없다고 하니 사용은 해야겠는데 기왕 쓰는 거 좀 더 편하게 환경설정해놓고 쓰는 게 좋겠다고 생각되어 여러 블로그들을 배회하며 필요한 것들을 긁어모아봤다. home 디렉토리에 .vimrc 파일을 만들어 다음의 내용으로 채워 넣는다. If has(“syntax”) syntax on“① 문법 강조 endif "② 들여쓰기 설정" set autoindent set cindent set ts=4 “Tab size set shiftwidth=4 “Auto indent size "③ 줄번호..
-
Blink 앱을 활용한 iPad 코딩ETC 2020. 9. 17. 13:46
가볍게 소스코드를 수정하고 배포하는 것 정도는 iPad를 통해 할 수 있으면 좋겠다고 생각하고 있었다. 그러던 중 "개발자 맛"님의 유튜브 영상을 통해 터미널 앱인 Blink와 구글 클라우드 VM을 Mosh로 연결하여 사용할 수 있다는 것을 알게 되었다. 바로 이거다 싶어 앱스토어에서 25,000원의 거금을 들여 Blink라는 터미널 앱을 지르게 되었는데... 개발자 맛 님의 영상 (youtu.be/Q-YOahQso1A) 영상 내용을 요약하자면 구글 클라우드에서 인스턴스를 생성 blink에 ssh 키(private + public) 생성. 인스턴스에 public 키 적용 iPad에서 ssh 또는 mosh를 통해 인스턴스에 접속 하지만 진행하다 보니 몇 가지 문제에 봉착하게 되었다. VM 생성 후 공개키를..