본문 바로가기

Programming

(136)
[Project Euler] Problem 018 12345678910111213141516171819202122232425262728293031323334public class Problem018 { public static void main(String[] args) { System.out.println(run()); } public static String run() { int[][] arr = { {75}, {95, 64}, {17, 47, 82}, {18, 35, 87, 10}, {20, 4, 82, 47, 65}, {19, 1, 23, 75, 3, 34}, {88, 2, 77, 73, 7, 63, 67}, {99, 65, 4, 28, 6, 16, 70, 92}, {41, 41, 26, 56, 83, 40, 80, 70, 33}, {41, 48..
[BAEKJOON] 2581번 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960#include #include int is_prime(int n); int main(){ int m, n; int sum = 0; int i; int min = -1; scanf("%d", &m); scanf("%d", &n); for (i = m; i
[BAEKJOON] 1978번 123456789101112131415161718192021222324252627282930313233343536373839404142#include int is_prime(int n); int main(){ int n; int i; int count = 0; int lim; scanf("%d", &lim); for (i = 0; i
스트림 1. 입력과 출력 그동안 입력이라는 말과 출력이라는 말을 꽤 많이 사용해 왔다. 그렇다면 다음과 같은 질문에 답할 수 있을까? 무엇이 입력인가? 무엇이 출력인가? 입력은 무언가가 들어가는 것이고, 출력은 무언가가 나오는 것이다. 결국 중요한 것은 어디서 들어가는가, 어디서 나오는가다. 그리고 어디, 그러니까 기준이 되는 곳은 프로그램이다. scanf 함수는 키보드로부터 입력받는다. 다시 말해 키보드에서 프로그램으로 입력받는다. printf 함수는 모니터로 출력한다. 다시 말해 프로그램에서 모니터로 입력받는다. 2. 스트림 그런데 어떻게 키보드에서 입력한 내용이 프로그램으로 전달되는 걸까? 프로그램과 키보드가 뭔가 통신이라도 하는 걸까? 프로그램과 키보드, 프로그램과 모니터는 기본적으로 떨어져 있다. 연결..
[Project Euler] Problem 017 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 import java.util.HashMap; import java.util.Map; public class Problem017 { public static void main(String[] args) { System.out.println(run()); } public static String run() { Map map = new HashMap(); int result = "..
BigInteger 클래스 큰 정수에 대해 연산할 때 유용한 클래스. 1. Fields public static final BigInteger ONE;public static final BigInteger TEN;public static final BigInteger ZERO; 각각 값이 1, 10, 0인 BigInteger 객체다. 이 상수 필드들은 연산 시 유용하게 사용된다.BigInteger 클래스의 연산 메소드는 BigInteger 객체를 매개값으로 받아 연산하기 때문이다. 2. Constructors ① public BigInteger(byte[] val) val의 각 요소를 1바이트로 간주해 little-endian 방식으로 채운 값을 반환한다.예를 들어 val = {1, 0}으로 초기화되었을 경우 BigInteger ..
[Project Euler] Problem 016 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950public class Problem016 { private final static int A = 2; private final static int N = 1000; public static void main(String[] args) { System.out.println(run()); } public static String run() { int[] arr = new int[350]; int sum = 0; /*Initialize array by -1*/ for(int i = 0; i = 0) && (j > 0); --j) { if(arr[j..
[Project Euler] Problem 015 를 계산하면 된다. 문제는 분자의 값이 너무 커서 8바이트 자료형으로도 저장할 수 없다는 것. 따라서 40!과 20!20!을 한 번에 계산하고 나누는 것이 아니라 하나씩 나눈다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public class Problem015 { private static final int V = 20; private static final int H = 20; public static void main(String[] args) { System.out.println(run()); } public static String run() { long result = 1L; for(int i = 0; i