백준 알고리즘
-
[JAVA] 1748번: 수 이어 쓰기1Algorithm/백준 알고리즘 2021. 7. 20. 11:39
문제 설명 1부터 N까지의 수를 이어서 쓰면 다음과 같이 새로운 하나의 수를 얻을 수 있다. 이렇게 만들어진 새로운 수는 몇 자리 수일까? 이 수의 자릿수를 구하는 프로그램을 작성하시오. 1234567891011121314151617181920212223... 입력 첫째 줄에 N(1 ≤ N ≤ 100,000,000)이 주어진다. 출력 첫째 줄에 새로운 수의 자릿수를 출력한다. 풀이 1. length변수를 선언하여 i가 length와 일치할 경우 length * 10을 해준다. => 2자릿수, 3자릿수.. 2. 자릿수가 증가함에 따라 자릿수당 해당 숫자가 위치해야함으로 cnt를 1증가 시켜준다. 3. 해당 자리만큼 temp에 cnt를 더해준다. 코드 /* - 1부터 N까지의 수를 이어서 쓰면 다음과 같이 ..
-
[JAVA] 1158번: 요세푸스 문제Algorithm/백준 알고리즘 2021. 7. 6. 13:56
문제 설명 1번부터 N번까지 N명의 사람이 원을 이루면서 앉아있고, 양의 정수 K(≤ N)가 주어진다. 이제 순서대로 K번째 사람을 제거한다. 한 사람이 제거되면 남은 사람들로 이루어진 원을 따라 이 과정을 계속해 나간다. 이 과정은 N명의 사람이 모두 제거될 때까지 계속된다. 원에서 사람들이 제거되는 순서를 (N, K)-요세푸스 순열이라고 한다. 예를 들어 (7, 3)-요세푸스 순열은 이다. N과 K가 주어지면 (N, K)-요세푸스 순열을 구하는 프로그램을 작성하시오. 입력 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 5,000) 출력 예제와 같이 요세푸스 순열을 출력한다. 풀이 1회차: 1, 2, 3, 4, 5, 6, 7 => 3저장 2회차: 4, 5, 6, ..
-
[JAVA] 1406번 : 에디터Algorithm/백준 알고리즘 2021. 7. 5. 17:11
문제 설명 한 줄로 된 간단한 에디터를 구현하려고 한다. 이 편집기는 영어 소문자만을 기록할 수 있는 편집기로, 최대 600,000글자까지 입력할 수 있다. 이 편집기에는 '커서'라는 것이 있는데, 커서는 문장의 맨 앞(첫 번째 문자의 왼쪽), 문장의 맨 뒤(마지막 문자의 오른쪽), 또는 문장 중간 임의의 곳(모든 연속된 두 문자 사이)에 위치할 수 있다. 즉 길이가 L인 문자열이 현재 편집기에 입력되어 있으면, 커서가 위치할 수 있는 곳은 L+1가지 경우가 있다. 이 편집기가 지원하는 명령어는 다음과 같다. L 커서를 왼쪽으로 한 칸 옮김 (커서가 문장의 맨 앞이면 무시됨) D 커서를 오른쪽으로 한 칸 옮김 (커서가 문장의 맨 뒤이면 무시됨) B 커서 왼쪽에 있는 문자를 삭제함 (커서가 문장의 맨 앞이..