[TopCoder]SRM 437 Div2 250

Problem Statement
   
There is nothing more beautiful than just an integer number.
The beauty of an integer is the number of distinct digits it contains in decimal notation.
You are given an integer number n. Return the beauty of this number.

특정 숫자가 몇 종류의 수를 사용해서 표현되는지 구하라.(이런 막장번역에 의존하기 보다는 아래의 예제를 보는게 더 좋을지도)

Definition
   
Class:
TheBeauty
Method:
find
Parameters:
int
Returns:
int
Method signature:
int find(int n)
(be sure your method is public)
   

Constraints
-
n will be between 1 and 1,000,000,000, inclusive.

Examples
0)
7
Returns: 1
Just one digit.

1)
100
Returns: 2
Two distinct digits - 0 and 1.

2)
123456789
Returns: 9
All the digits are different.

3)
1000000000
Returns: 2

4)
932400154
Returns: 7

일단 안 털린 소스, 발로 작성됨(Java)
public class TheBeauty {
    public int find(int n) {
        boolean numExist[] = new boolean[10]; //0~9가 존재하는지 저장하는 배열
        //initialize
        for(int i = 0 ; i < 10 ; i++) {
            numExist[i] = false; //일단 숫자가 존재하지 않는다고 초기화
        }
       
        while(n > 0) {
            int num = n % 10;
            n = n / 10;
           
            numExist[num] = true; //숫자가 존재하면 존재확인용 배열을 true로 수정
        }
        //numExist배열에서 true의 갯수가 등장하는 숫자의 갯수이다
        int count = 0;
        for(int i = 0 ; i < 10 ; i++) {
            if(numExist[i] == true) {
                count++;
            }
        }
       
        return count;
    }
}

by Otacomm | 2009/03/25 02:00 | 트랙백 | 덧글(0)

트랙백 주소 : http://otacomm.egloos.com/tb/4839084
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글

◀ 이전 페이지 다음 페이지 ▶