알고리즘 풀이/백준(BOJ)

[JAVA]백준알고리즘 11720/11721/15552/11721 정리

닥스훈스 2019. 1. 24. 17:43

[11720]

자바에서 입력 받는 자료형에 따른 메소드

byte : nextByte()

short : nextShort()

int : nextInt()

long : nextLong()

float : nextFloat()

double : nextDouble()

String : next(), nextLine()

boolean : nextBoolean()


String 자료형은 next()와 nextLine()메소드

next(): 공백단위,  nextLine()은 엔터 단위


charAt() : 주어진 값에 해당하는 문자열을 리턴한다.


**String클래스 메소드 정리

http://www.dreamy.pe.kr/zbxe/CodeClip/3766960


string->char->int


1)string->char

문자열의 길이(= n)만큼 반복하면서 한 글자씩 숫자로 변경


2)char->int

①ASCII code를 활용하는 방법: int 형과 char 형에 +또는 - 연산자를 사용할 경우 char형이 int 형으로 변환되어 계산됩니다. 이를 활용하여 처리합니다.

②Integer 클래스의 parseInt와 String 클래스의 substring을 활용하는 방법: 입력값이 모두 숫자이므로 int형으로 강제 형변환하여 처리합니다..


[11721]

처음생각: substring()으로 시도해보기

++i와 i++의 차이점, if문의 위치에 따라서 결과값이 바뀐다.

charAt은 0부터 시작한다.


[15552]

Scanner과 BufferedReader의 차이점


[11721]

String[] split = n.split(" ");

int[] word = Arrays.stream(split).mapToInt(Integer::parseInt).toArray();

버블소트(i와 j의 값, 몇번 돌아가는지 등등)=>다양한 방법 찾아보기