반응형

정수 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.programming-challenges.com 들어가서 돌려보면 계속 틀렸다고 나온다 -_-;;젠장 . 뭐가 문제야

  1. import java.io.*;
  2.  
  3. class Main implements Runnable{
  4.     static String ReadLn(int maxLength){  // utility function to read from stdin,
  5.                                           // Provided by Programming-challenges, edit for style only
  6.         byte line[] = new byte [maxLength];
  7.         int length = 0;
  8.         int input = -1;
  9.         try{
  10.             while (length < maxLength){//Read untill maxlength
  11.                 input = System.in.read();
  12.                 if ((input < 0) || (input == ' ')) break//or untill end of line ninput
  13.                 line [length++] += input;
  14.             }
  15.  
  16.             if ((input < 0) && (length == 0)) return null;  // eof
  17.             return new String(line, 0, length);
  18.         }catch (IOException e){
  19.             return null;
  20.         }
  21.     }
  22.  
  23.     public static void main(String args[])  // entry point from OS
  24.     {
  25.         Main myWork = new Main();  // Construct the bootloader
  26.         myWork.run();            // execute
  27.     }
  28.  
  29.     public void run() {
  30.         new MyStuff().run();
  31.     }
  32. }
  33.  
  34. class MyStuff implements Runnable{
  35.     public void run(){
  36.             String input = (Main.ReadLn(20));
  37.             calcCycle(input);       
  38.     }
  39.    
  40.     // You can insert more classes here if you want.
  41.    
  42.     public void calcCycle(String input){
  43.         String[] inputArray     = input.trim().split(" ");
  44.         int startInput    = Integer.parseInt(inputArray[0]);
  45.         int endInput          = Integer.parseInt(inputArray[1]);
  46.         int maxCount            = 0;
  47.         int maxNumber         = 0;
  48.        
  49.         if (startInput > endInput){
  50.             int temp    = endInput;
  51.             endInput        = startInput;
  52.             startInput  = temp;
  53.         }
  54.                
  55.         while(startInput <= endInput){    
  56.             int count      = 1;             
  57.             int number   = startInput;
  58.            
  59.             if (number != 1){
  60.                 while (number > 1){
  61.                     if (number % 2 == 0){
  62.                         number = number /2;
  63.                     }else {        
  64.                         number = number * 3 + 1;           
  65.                     }
  66.                     count++;
  67.                 }             
  68.             }
  69.  
  70.             if (maxCount < count){
  71.                 maxCount    = count;
  72.             }
  73.             startInput++;
  74.         }
  75.  
  76.         System.out.println( inputArray[0] + " " + inputArray[1] + " " + maxCount);
  77.     }
  78.    
  79. }


728x90
반응형

'Development > Algorithm' 카테고리의 다른 글

에라토스테네스의 체  (0) 2016.12.07
[Try-catch]대문자 출력  (0) 2013.11.04
[Programing Challenges]반전한 수 더하기  (0) 2013.02.12
[Hacker Cup]Find the Min  (0) 2013.02.01
[Hacker Cup]Balanced Smileys  (0) 2013.01.31
반응형
DB : Oarcle

SELECT A.TABLE_NAME as 테이블명
     , B.COMMENTS as 테이블한글명
     , A.COLUMN_NAME as 컬럼명
     , C.COMMENTS as 컬럼한글명
     , A.DATA_LENGTH
     , A.DATA_TYPE     
     , A.NULLABLE
     , D.CONSTRAINT_NAME
     , D.CONSTRAINT_TYPE
FROM   ALL_TAB_COLUMNS A
, ALL_TAB_COMMENTS B
     , ALL_COL_COMMENTS C
     , ALL_CONSTRAINTS  D
WHERE  A.TABLE_NAME = B.TABLE_NAME
  AND  A.TABLE_NAME = C.TABLE_NAME
  AND  A.TABLE_NAME = D.TABLE_NAME
  AND  A.COLUMN_NAME = C.COLUMN_NAME
  AND  A.TABLE_NAME = :tableNm

CONSTRAINT_TYPE 을 'P' 로 설정해주면 입력한 테이블의 PK만 조회 가능하다. !

 
  
728x90
반응형
반응형
ColumnDatatypeNULLDescription
OWNER VARCHAR2(30) NOT NULL Owner of the object
TABLE_NAME VARCHAR2(30) NOT NULL Name of the object
COLUMN_NAME VARCHAR2(30) NOT NULL Name of the column
COMMENTS VARCHAR2(4000)   Comment on the column


테이블의 컬럼명과 컬럼 한글명을 검색할때 사용하면 된다. 

출처 : ORACLE DOCUMENTATION LIBRARY 
728x90
반응형
반응형
ColumnDatatypeNULLDescription
OWNER VARCHAR2(30) NOT NULL Owner of the object
TABLE_NAME VARCHAR2(30) NOT NULL Name of the object
TABLE_TYPE VARCHAR2(11)   Type of the object
COMMENTS VARCHAR2(4000)   Comment on the object


테이블 명을 알고 싶을때 사용하면 유용하다.!

출처 : ORACLE DOCUMENTATION LIBRARY 
728x90
반응형
반응형
Column              DatatypeNULLDescription
OWNER VARCHAR2(30) NOT NULL Owner of the constraint definition
CONSTRAINT_NAME VARCHAR2(30) NOT NULL Name of the constraint definition
CONSTRAINT_TYPE VARCHAR2(1)   Type of the constraint definition:
  • C - Check constraint on a table

  • P - Primary key

  • U - Unique key

  • R - Referential integrity

  • V - With check option, on a view

  • O - With read only, on a view

  • H - Hash expression

  • F - Constraint that involves a REF column

  • S - Supplemental logging

TABLE_NAME VARCHAR2(30) NOT NULL Name associated with the table (or view) with the constraint definition
SEARCH_CONDITION LONG   Text of search condition for a check constraint
R_OWNER VARCHAR2(30)   Owner of the table referred to in a referential constraint
R_CONSTRAINT_NAME VARCHAR2(30)   Name of the unique constraint definition for the referenced table
DELETE_RULE VARCHAR2(9)   Delete rule for a referential constraint:
  • CASCADE

  • SET NULL

  • NO ACTION

STATUS VARCHAR2(8)   Enforcement status of the constraint:
  • ENABLED

  • DISABLED

DEFERRABLE VARCHAR2(14)   Indicates whether the constraint is deferrable (DEFERRABLE) or not (NOT DEFERRABLE)
DEFERRED VARCHAR2(9)   Indicates whether the constraint was initially deferred (DEFERRED) or not (IMMEDIATE)
VALIDATED VARCHAR2(13)   Indicates whether all data obeys the constraint (VALIDATED) or not (NOT VALIDATED)
GENERATED VARCHAR2(14)   Indicates whether the name of the constraint is user-generated (USER NAME) or system-generated (GENERATED NAME)
BAD VARCHAR2(3)   Indicates whether this constraint specifies a century in an ambiguous manner (BAD) or not (NULL). To avoid errors resulting from this ambiguity, rewrite the constraint using the TO_DATE function with a four-digit year.

See Also: the TO_DATE function in Oracle Database SQL Language Reference and Oracle Database Advanced Application Developer's Guide

RELY VARCHAR2(4)   Indicates whether an enabled constraint is enforced (RELY) or unenforced (NULL)

See Also: the constraints in Oracle Database SQL Language Reference

LAST_CHANGE DATE   When the constraint was last enabled or disabled
INDEX_OWNER VARCHAR2(30)   Name of the user owning the index
INDEX_NAME VARCHAR2(30)   Name of the index (only shown for unique and primary-key constraints)
INVALID VARCHAR2(7)   Indicates whether the constraint is invalid (INVALID) or not (NULL)
VIEW_RELATED VARCHAR2(14)   Indicates whether the constraint depends on a view (DEPEND ON VIEW) or not (NULL)


테이블의 PK, FK등을 찾을수 있다. 테이블에서 지정되어있는 not null 여부도 이 테이블을 조회해보면 확인할 수 있다.

출처 : ORACLE DOCUMENTATION LIBRARY
728x90
반응형
반응형
ColumnDatatypeNULLDescription
OWNER VARCHAR2(30) NOT NULL Owner of the constraint definition
CONSTRAINT_NAME VARCHAR2(30) NOT NULL Name of the constraint definition
TABLE_NAME VARCHAR2(30) NOT NULL Name of the table with the constraint definition
COLUMN_NAME VARCHAR2(4000)   Name of the column or attribute of the object type column specified in the constraint definition
      Note: If you create a constraint on a user-defined REF column, the system creates the constraint on the attributes that make up the REF column. Therefore, the column names displayed in this view are the attribute names, with the REF column name as a prefix, in the following form:

"REF_name"."attribute"

POSITION NUMBER   Original position of the column or attribute in the definition of the object

ALL_CONS_COLUMNS을 조회하면 위에 정보를 알수 있다. 
그리고 테이블별로 CONSTRAINT_NAME 을 알수 있기 때문에 테이블의 PK 도 조회 가능하다.  

출처 : ORACLE DOCUMENT LIBRARY 
728x90
반응형
반응형

cross-cutting-concerns(횡단관심사) : 한 어플리케이션이 여러부분에 걸쳐있는 기능
aspect-oriented programming(AOP) : 횡단 관심사의 분리를 위한것 


 용어  정의
advice aspect가 해야할 작업. aspect가 '무엇'을 '언제'할지를 정의한다. 
joinpoint advice를 적용할수 있는곳, 어플리케이션 실행에 aspect를 끼워넣을수 있는 지점. 
pointcut aspect가 advice할 joinpoint 영역을 좁힌다. '어디서' 하는것을 정의한다. 
aspect advice와 pointcut을 합친것. '무엇','언제','어디서'가  앞의 2가지에 의해서 정의된다. 
target advice가 적용될 객체.  
proxy  advice를 taget 객체에 적용하면 생성되는 객체. taget객체와 proxy 객체는 차이가 없어야 한다.   
weaving target객체에 aspect를 적용해서 새로운 proxy 객체를 생성하는 절차. 
728x90
반응형
반응형

Factory Method 패턴에서는 객체를 생성하기 위한 인터페이스를 정의한다.

어떤 클래스를 만들지는 서브클래스에서 결정한다.

즉, 클래스의 인스턴스를 만드는 일을 서브클래스에 맡기게 된다.



Factory Method 구조?

abstract Product factoryMethod(String type)

abstract : 추상메소드로 선언하여 서브클래스에서 객채 생성을 책임진다.

Product : 특정 객체를 리턴한다. 

type : 매개변수를 써서 만들어낼 객체 종류를 선택할수 있다.


DIP : Dependency Inversion Principle

구상 클래스에 의존하지 않고 추상화된 것에 의존하도록 만들어라!


Product를 구현하는 ConcreteProduct 의 종류가 다양해져도 Creator는 Product를 바라보고 있기 때문에

소스에 변화가 없다. 

728x90
반응형

'Development > Design Pattern' 카테고리의 다른 글

Strategy Pattern  (0) 2013.07.02
[데코레이터 패턴]  (0) 2013.06.26
Decorator Pattern  (0) 2011.08.30
Template Method Pattern  (0) 2011.08.30
반응형


객체에 추가적인 요건을 동적으로 첨가할수 있다.

데코레이터는 서브클래스를 만드는것을 통해서 기능을 유연하게 확장할 수 있는 방법은 제공한다.



Decorator가 Component를 상속받음으로써 ConcreteDecorator들의 형식을 동일하게 맞출 수 있다.

그래서 Component에 여러개의 ConcreteDecorator들을 충첩시킬수도 있다.

728x90
반응형

'Development > Design Pattern' 카테고리의 다른 글

Strategy Pattern  (0) 2013.07.02
[데코레이터 패턴]  (0) 2013.06.26
Factory Method Pattern  (0) 2011.08.30
Template Method Pattern  (0) 2011.08.30

+ Recent posts