-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sort/bigInteger
- Loading branch information
Showing
7 changed files
with
373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package bigInteger; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.math.BigInteger; | ||
|
||
/* | ||
* 작성일 : 2018년 07월 15일 | ||
* 내 용 : 큰 수 A+B | ||
* A+B를 계산하시오. | ||
*/ | ||
public class Code_10757 { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// TODO Auto-generated method stub | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
String[] arr=br.readLine().split(" "); | ||
|
||
BigInteger a = new BigInteger(arr[0]); | ||
|
||
BigInteger b = new BigInteger(arr[1]); | ||
|
||
System.out.println(a.add(b)); | ||
|
||
//Scanner를 이용하면 좀 더 편히 구현할 수 있다. | ||
// BigInteger a = sc.nextBigInteger(); 로 입력받는 순간 변수에 넣을 수 있음. | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package bigInteger; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.math.BigInteger; | ||
|
||
/* | ||
* 작성일 : 2018년 07월 15일 | ||
* 내 용 : 피보나치 수 4 | ||
* n이 주어졌을 때, n번째 피보나치 수를 구하는 프로그램을 작성하시오. | ||
* n은 10,000보다 작거나 같은 자연수 또는 0이다. | ||
*/ | ||
public class Code_10826 { | ||
|
||
static BigInteger[] arr = new BigInteger[10000]; | ||
|
||
public static void main(String[] args) throws NumberFormatException, IOException { | ||
// TODO Auto-generated method stub | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
int num = Integer.parseInt(br.readLine()); | ||
|
||
System.out.println(pibonacci(num)); | ||
|
||
} | ||
|
||
static BigInteger pibonacci(int num) { | ||
|
||
if(arr[num]!=null) return arr[num]; | ||
|
||
else { | ||
System.out.println(num); | ||
BigInteger i = new BigInteger(String.valueOf(num)); | ||
if(i.equals(BigInteger.ZERO) || i.equals(BigInteger.ONE)) { | ||
return arr[num] = i; | ||
} | ||
else { | ||
BigInteger e = pibonacci(num-1).add(pibonacci(num-2)); | ||
return arr[num] = e; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package bigInteger; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Scanner; | ||
|
||
/* | ||
* 작성일 : 2018년 07월 15일 | ||
* 내 용 : a^b | ||
* 실수 a와 정수 b가 주어졌을 때, a의 b제곱을 정확하게 계산하는 프로그램을 작성. | ||
*/ | ||
|
||
public class Code_10827 { | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
Scanner input = new Scanner(System.in); | ||
|
||
String[] arr = input.nextLine().split(" "); | ||
|
||
BigDecimal a = new BigDecimal(arr[0]); | ||
|
||
int b = Integer.parseInt(arr[1]); | ||
|
||
BigDecimal c = a.pow(b); | ||
System.out.println(c.toPlainString()); | ||
//toPlainString() : BigDecimal를 표현할 때 과학적 표기를 사용하지 않음. | ||
//toString() : BigDecimal를 표현할 때 과학적 표기를 사용함. | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package sort; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/* | ||
* 작성일 : 2018년 07월 15일 | ||
* 내 용 : 백준11650 -2차원 평면 위의 점 N개가 주어진다. | ||
* 좌표를 x좌표가 증가하는 순으로, x좌표가 같으면 y좌표가 증가하는 순서로 | ||
* 정렬한 다음 출력하는 프로그램을 작성하시오. | ||
*/ | ||
public class Code_11650_Comparable { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// TODO Auto-generated method stub | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
List<Point> list = new ArrayList<Point>(); | ||
|
||
String [] arr = new String[2]; | ||
|
||
int num = Integer.parseInt(br.readLine()); | ||
|
||
for(int i=0; i<num; ++i) { | ||
arr = br.readLine().split(" "); | ||
Point p = new Point(Integer.parseInt(arr[0]),Integer.parseInt(arr[1])); | ||
list.add(p); | ||
} | ||
|
||
Collections.sort(list); | ||
|
||
/** | ||
34줄과 같은 결과 | ||
Collections.sort(list, new Comparator<Point>() { | ||
@Override | ||
public int compare(Point p1, Point p2) { | ||
return p1.compareTo(p2); | ||
} | ||
}); | ||
**/ | ||
|
||
for(Point p : list) | ||
System.out.println(p.toString()); | ||
} | ||
|
||
} | ||
|
||
class Point implements Comparable<Point>{ | ||
int x; | ||
int y; | ||
|
||
public Point(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public void setX(int x) { | ||
this.x = x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public void setY(int y) { | ||
this.y = y; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return x + " " + y ; | ||
} | ||
|
||
@Override | ||
public int compareTo(Point p) { | ||
int r = this.x - p.x; | ||
if(r!=0) return r; | ||
else return this.y - p.y; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package test; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/* | ||
* 작성일 : 2018년 07월 15일 | ||
* 내 용 : 백준11650 -2차원 평면 위의 점 N개가 주어진다. | ||
* 좌표를 x좌표가 증가하는 순으로, x좌표가 같으면 y좌표가 증가하는 순서로 | ||
* 정렬한 다음 출력하는 프로그램을 작성하시오. | ||
*/ | ||
public class Code_11650_Comparator { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// TODO Auto-generated method stub | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
List<Point> list = new ArrayList<Point>(); | ||
|
||
String [] arr = new String[2]; | ||
|
||
int num = Integer.parseInt(br.readLine()); | ||
|
||
for(int i=0; i<num; ++i) { | ||
arr = br.readLine().split(" "); | ||
Point p = new Point(Integer.parseInt(arr[0]),Integer.parseInt(arr[1])); | ||
list.add(p); | ||
} | ||
|
||
Collections.sort(list, new PointComparator()); | ||
|
||
for(Point p : list) | ||
System.out.println(p.toString()); | ||
} | ||
|
||
} | ||
|
||
class Point{ | ||
int x; | ||
int y; | ||
|
||
public Point(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public void setX(int x) { | ||
this.x = x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public void setY(int y) { | ||
this.y = y; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return x + " " + y ; | ||
} | ||
} | ||
|
||
class PointComparator implements Comparator<Point>{ | ||
@Override | ||
public int compare(Point p1, Point p2) { | ||
int r = p1.x - p2.x; | ||
if(r!=0) return r; | ||
else return p1.y-p2.y; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package sort; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
/* | ||
* 작성일 : 2018년 07월 15일 | ||
* 내 용 : 백준11650 -2차원 평면 위의 점 N개가 주어진다. | ||
* 좌표를 y좌표가 증가하는 순으로, y좌표가 같으면 x좌표가 증가하는 순서로 | ||
* 정렬한 다음 출력하는 프로그램을 작성하시오. | ||
* Point클래스 11650에 있음! | ||
*/ | ||
|
||
public class Code_11651{ | ||
|
||
public static void main(String[] args) throws IOException { | ||
// TODO Auto-generated method stub | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
List<Point> list = new ArrayList<Point>(); | ||
|
||
String [] arr = new String[2]; | ||
|
||
int num = Integer.parseInt(br.readLine()); | ||
|
||
for(int i=0; i<num; ++i) { | ||
arr = br.readLine().split(" "); | ||
Point p = new Point(Integer.parseInt(arr[0]),Integer.parseInt(arr[1])); | ||
list.add(p); | ||
} | ||
|
||
//Collections.sort(list, new PointYComparator()); | ||
|
||
|
||
Collections.sort(list, new Comparator<Point>() { | ||
@Override | ||
public int compare(Point p1, Point p2) { | ||
int r = p1.y - p2.y; | ||
if(r!=0) return r; | ||
return p1.x - p2.x; | ||
} | ||
}); | ||
|
||
|
||
for(Point p : list) | ||
System.out.println(p.toString()); | ||
} | ||
|
||
} | ||
|
||
class PointYComparator implements Comparator<Point>{ | ||
@Override | ||
public int compare(Point p1, Point p2) { | ||
int r = p1.y - p2.y; | ||
if(r!=0) return r; | ||
return p1.x - p2.x; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package sort; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/* | ||
* 작성일 : 2018년 07월 14일 | ||
* 내 용 : 백준2750 -N개의 수가 주어졌을 때, 이를 오름차순으로 정렬하는 프로그램을 작성하시오. | ||
*/ | ||
public class Code_2750 { | ||
|
||
public static void main(String[] args) throws IOException { | ||
// TODO Auto-generated method stub | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
List<Integer> list = new ArrayList<Integer>(); | ||
|
||
int num = Integer.valueOf(br.readLine()); | ||
|
||
for(int i=0; i<num; ++i) { | ||
list.add(Integer.valueOf(br.readLine())); | ||
} | ||
|
||
Collections.sort(list); | ||
|
||
for(int i : list) | ||
System.out.println(i); | ||
} | ||
|
||
} |