본문 바로가기

728x90
반응형

Development/Algorithm

(6)
에라토스테네스의 체 고대 그리스 수학자 에라토스테네스가 발견한 소수를 찾는 방법이다. N까지의 수중에 소수를 판단하는 상황이 생길 경우 유용하다. 123456789101112131415161718192021private static void primeNumber(int n){ // 에라토스테네스의 체 // N 보다 작은 소수를 구한다. boolean[] arr = new boolean[n+1]; Arrays.fill(arr, true); for (int i=2; i
[Try-catch]대문자 출력 문자열에서 첫번째 대문자를 찾아서 출력한다. (출처 : http://www.try-cat.ch/contest/view/exercise/70)import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); String data = input.nextLine(); char result = ' '; for (int i=0; i=65 && charData
[Programing Challenges]반전한 수 더하기 맬리드네시아(Malidnesia)의 고대 희극인들은 비극보다 희극을 선호한다. 불행히도 고대 연극의 대부분은 비극이다. 따라서, ACM의 드라마 작가는 몇 편의 비극을 희극으로 바꾸기로 결정한다. 극의 모든 것을 반대로 바꿔야 함에도 불구하고 극의 기본 의미를 보존해야 하기 때문에 이 작업이 매우 어렵다는 것은 분명하다. 숫자를 예로 들어보자. 비극에서 어떤 숫자가 나타나면 희극에서 사용하기 전에 이 숫자를 거꾸로 변환해야 한다. 거꾸로 쓴 숫자(Reversed number)라는 것은 비트 순서를 반대로 하는 것이 아니라 아라비아 숫자를 반대로 쓰는 것을 의미한다. 첫번째 자리가 마지막이 되고, 마지막이 첫번째가 되는 것이다. 예를 들어, 주인공이 비극에서 1245 딸기(1245 strawberries)..
[Hacker Cup]Find the Min After sending smileys, John decided to play with arrays. Did you know that hackers enjoy playing with arrays? John has a zero-based index array, m, which contains n non-negative integers. However, only the first k values of the array are known to him, and he wants to figure out the rest.John knows the following: for each index i, where k
[Hacker Cup]Balanced Smileys 흠... 왜 이렇게 생각을 못했을까 Balanced SmileysYour friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to express himself through emoticons, he hates unbalanced parenthesis so much that it makes him go :(Sometimes he puts emoticons within parentheses, and you find it hard to tell if a parenthesis really is a parenthesis or part of an emoticon.A me..
[Programming Challenges] The 3n+1 Problem 정수 n에서 시작해 n이 짝수면 2로 나누고 홀수면 3을 곱한 다음 1을 더한다. 이렇게 해서 새로 만들어진 숫자를 n으로 놓고 n=1이 될때까지 같은 작업을 반복한다. 1이 나올때까지 만들어진 수의 개수(1포함)를 n의 사이클 길이라고 한다. 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 22의 사이클은 16 입력 - 입력은 일련의 정수 쌍 i와 j로 구성되며 한 줄에 한쌍의 수가 입력된다. 모든 정수는 1,000,000보다 작고 0보다 크다 출력 - i, j를 입력된 순서대로 출력 - i, j의 최대 사이클 길이 출력 입력 예 출력 예 1 10 1 10 20 100 200 100 200 125 210 210 201 210 89 풀이) 풀긴 했는데 http://www.pr..

728x90
반응형