2017년 1월 19일 목요일

[JAVA]압력계산


힘과 넓이를 입력받아 물체의 압력을 계산하는 프로그램


1] 문제
P 102 9: 크기 P인 힘이 넓이 S인 물체에 균일하게 미치고 있는 경우 압력의 세기는 p = P/S 로 정의된다. 사용자로부터 물체에 주어진 힘과 물체의 면적을 입력받아서 압력의 세기를 계산하는 프로그램을 작성하시오.
 
 
2] 알고리즘 및 설명
Step 1 : 사용자로부터 입력받을 힘(f)과 넓이(s), 그 결과를 출력하는 변수(press)들을 정의한다.
Step 2 : 데이터를 읽는 기능을 가진 Scanner클래스를 선언하여 힘과 넓이를 입력 받는다.
Step 3 : 압력의 세기를 구해 결과 값을 변수(press)에 입력받는다.
Step 4 : 출력함수를 이용하여 결과 값을 확인한다.
 
 
3] 프로그램 코드
import java.util.Scanner;
 
public class Assign_2 {
  public static void main(String args[]){
 
  int f,p;
  double press;
 
  Scanner input = new Scanner(System.in);
 
  System.out.println("힘의 크기와 물체의 넓이를 입력하시오");
  f = input.nextInt();
  p = input.nextInt();
 
  press=(double)f/p;
  System.out.println("압력의 세기는 "+press);
 
  input.close();
  }
}



[Algorithm]퀵 정렬(Quick Sort)


퀵 정렬은 합병정렬과 같이 분할-정복-합병의 순서대로 동작하는데, 분할에서 다른 점이 있다. 합병정렬은 N개의 배열을 N/2로 분할 하였다면, 퀵 정렬은 pivot이라는 기준점으로 분할을 한다.


위 그림과 같이 왼쪽은 pivot보다 작은수 오른쪽은 큰 수로 배열 요소의 위치를 지정한다.



Recursive로 분할을 반복하고 partiton함수를 통해 pivot의 위치를 반환받는다. 



partition함수의 동작 순서를 보자. 배열 마지막 15가 pivot으로 정하고 i는 pivot보다 작은 수들의 기준, j는 반복문을 돌릴 변수이다.

1) j가 증가함에 따라 pivot인 15와 비교한다.
2) Arr[ j ] > 15 이면 j++. 아무일도 일어나지 않는다.
2-1) Arr[ j ] <= 15 이면 i++ 하고 Arr[ i ]와 Arr[ j ]를 바꾼다. 다시 j++
3) j가 pivot인 15의 앞 요소까지 오게 되면, i는 현재 15보다 작은 마지막 배열 요소를 가리키고 있다. Arr[ i+1 ] 과 pivot의 자기를 바꾼다.



 설명의 코드는 위와 같다. X는 pivot이고 j는 for문으로 돌린다.


code]
package test;
public class quickSort {
public static void main(String[] args) {
int data[] = {1,3,5,2,8,7,4,9,6,10};
quickSort(data, 0, data.length-1);
for(int c : data)
System.out.print(c+" ");
}
public static void quickSort(int data[], int start, int end) {
if(start < end) {
int pivotIdx = getPivot(data, start, end);
/*
for(int c : data)
System.out.print(c+" ");
System.out.println(" "+pivotIdx);
*/
quickSort(data, start, pivotIdx-1);
quickSort(data, pivotIdx + 1, end);
}
}
public static int getPivot(int data[], int start, int end) {
int i = start-1;
int pivot = data[end];
for(int j=start; j<=end-1; j++) {
if(data[j] <= pivot) {
int temp = data[++i];
data[i] = data[j];
data[j] = temp;
}
}
int temp = data[i + 1];
data[i + 1] = data[end];
data[end] = temp;
return i + 1;
}
}



2017년 1월 11일 수요일

[English]Day6


Concise : 짧고 간결한
ex)
Cut out unnecessary words or sentences if you want to make the essay more concise and effective. 
간결하고 효과적인 에세이를 쓰고자 한다면 불필요한 문장이나 단어들을 쓰지 마세요.

Baffle : 혼란시키다
ex)
I was getting a headache during the test because there were so many questions that baffle me.
시험보는 동안 나를 혼란시키는 문제들이 너무 많아서 머리가 아팠다.


There's a 60 percent chance of rain : 비가 올 확율이 60퍼센트 예요.
ex)
A : Look at those dark clouds building up on the horizon. Are we expecting  to have rain today?
B : There's 60 percent chance of rain.
A : Then, I'm going to get wet going home. I didn't bring an umbrella.
B : I have two. I can lend you one.


2017년 1월 10일 화요일

[English]Day5


Momentum : 힘, 탄력
ex)
With 5 minutes remaining on the clock, the team suddenly gained a momentum where they scored on every possession.
게임 종료 5분을 남겨놓고, 갑자기 팀은 탄력을 받아서 공격할 때마다 모드 득점을 했다.

Famished : 굶주린
ex)
Bryan was famished because he had no money to buy any food.
브라이언은 음식 사먹을 돈이 없어서 굶주리고 있었다.


I bought it just a few days ago, It's already coming apart. :
저는 이것을 단지 몇일 전에 구입했는데, 벌써 옷이 헤어지고 있어요.
ex)
A : Can I have this sweater exchanged?
B : What's the matter? Is it the wrong size?
A : I bought it just a few days ago, It's already coming apart.
B : I'll exchange it right away. 

come apart 흩어지다, 옷이 헤어지다.
activism 행동주의            taint 오명을 남기다 
overthrow 전복시키다      orchestrate 조직하다 
immerse ~에 몰두하다     imperialism 제국주의


2017년 1월 8일 일요일

[English]Day4


Cry me a river : 나에 비하면 아무것도 아니야.

Vacate : 비우다, 방을 빼다.
ex)
After getting several complaints for being noisy, the manager sent me a notice to vacate from my apartment. I'm so sad because I'm now homeless.
시끄럽다는 항의가 몇번 들어온 후, 관리인이 아파트를 비우라는 공문을 보냇어. 나는 이제 집 없는 노숙자신세라 슬퍼.

It does seem rather expensive : 
그것은 다소 비싸 보이는 군요
ex)
A : This is a beautiful sweater!
B : It's one of out best-selling ready to wear items.
A : It does rather expensive, though.
B : That's because it's 100 percent cashmere. It's really worth the price.

rather : 다소, 꽤 (rather than 차라리)

2017년 1월 6일 금요일

[English]Day3


You'll be getting a bonus and free merchandise from the company :
당신은 회사로부터 보너스와 상품을 받게 될거에요.
ex)
A : I overheard Mrs.D giving R some good news.
B : And what news is that, Ms.A?
A : You'll be getting a bonus and free merchandise from the company.
B : That's great news!

overheard : 우연히 듣다.

disseminate 퍼뜨리다 
mainstream 주류 
subjective 주관적인 
supplemental 추가, 보충되는 


stimulate 자극하다 
ethics 윤리 
acceptable 받아들여지는 
credentials 자격


2017년 1월 5일 목요일

[Hadoop] jps 명령어에 datanode 가 안보일 시


/hadoop/logs/ 에서 데이터노드의 로그를 보면 "all directories in dfs.datanode.data.dir are invalid"라고 써있다.
해결책은 /dfs/data 를 chmod로 755로 바꾸면 된다.

또 데이터노드 아이디가 맞지 않는다고 나올 때도 있는데(영어로) 이때는 /dfs/data 파일을 지웠다가 다시 생성해준다. 하둡 실행 중에 namenode초기화를 해서 id가 중복되었던 것 같다.