Skip to content

Commit

Permalink
Merge pull request #2 from yjll1019/master
Browse files Browse the repository at this point in the history
sort/bigInteger
  • Loading branch information
yjll1019 authored Jul 16, 2018
2 parents f6f2dd1 + 3d5af6c commit 362f7c9
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 26 deletions.
32 changes: 32 additions & 0 deletions bigInteger/Code_10757.java
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(); 로 입력받는 순간 변수에 넣을 수 있음.

}

}
45 changes: 45 additions & 0 deletions bigInteger/Code_10826.java
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;
}
}
}

}
30 changes: 30 additions & 0 deletions bigInteger/Code_10827.java
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를 표현할 때 과학적 표기를 사용함.
}

}
11 changes: 6 additions & 5 deletions collection/Code_1076.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ public static void main(String[] args) {
for(int i=0; i<3; ++i) {
list.add(input.nextLine());
}

String a = "";

// long value = 0;
for(int i=0; i<list.size()-1; ++i) {
//System.out.print(map.get(list.get(i)));
a += map.get(list.get(i));
// value = map.get(list.get(i))*10 + map.get(list.get(i));
}

int x = map.get(list.get(2));
long x = map.get(list.get(2));
for(int i=0; i<x; ++i) {
//System.out.print("0");
a += "0";
a+="0";
//value *= 10;
}
System.out.println(Integer.parseInt(a));
System.out.println(Long.parseLong(a));
}
}
10 changes: 5 additions & 5 deletions collection/Code_10845.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package collection;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Deque;
import java.util.Scanner;

/*
Expand All @@ -14,7 +14,7 @@ public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);

Queue<Integer> q = new ArrayDeque<Integer>();
Deque<Integer> q = new ArrayDeque<Integer>();

int num = input.nextInt();

Expand Down Expand Up @@ -52,15 +52,15 @@ else if(arr[0].equals("front")) {
System.out.println(q.peek());
}
}
/*

else if(arr[0].equals("back")) {
if(q.isEmpty()) {
System.out.println("-1");
}else {
System.out.println(q.);
System.out.println(q.peekLast());
}
}
*/

}
}

Expand Down
28 changes: 13 additions & 15 deletions collection/Code_1764.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,29 @@ public static void main(String[] args) {

ArrayList<String> list = new ArrayList<String>();

int hear = Integer.parseInt(a[0]);
int see = Integer.parseInt(a[1]);
int hear = Integer.parseInt(a[0]);//듣도 못한 사람의 수
int see = Integer.parseInt(a[1]);//보도 못한 사람의 수

Map<String, Integer> map = new HashMap<String,Integer>();

Map<String, String> map = new HashMap<String,String>();

for(int i=1; i<=(hear+see); ++i) {
if(i<=hear) {
map.put(input.nextLine(), "hear");
}
else if(i>=hear+2) {
String name = input.nextLine();
if(map.containsKey(name))
list.add(name);
String name = input.nextLine();


if(map.containsKey(name)) {
list.add(name);
}
else {
String n = input.nextLine();
map.put(name, 0);
}
}

System.out.println(list.size());

Collections.sort(list);
System.out.println(list.size());

for(String t : list)
System.out.println(t);
for(String ss : list)
System.out.println(ss);
}

}
2 changes: 1 addition & 1 deletion io/Code_1000.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public static void main(String[] args) {
int a = input.nextInt();
int b = input.nextInt();

System.out.println("A+B = "+(a+b));
System.out.println(a+b);
}
}
90 changes: 90 additions & 0 deletions sort/Code_11650_Comparable.java
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;
}

}

80 changes: 80 additions & 0 deletions sort/Code_11650_Comparator.java
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;
}
}
Loading

0 comments on commit 362f7c9

Please sign in to comment.