24h購物| | PChome| 登入
2012-11-11 11:27:49| 人氣1,381| 回應0 | 上一篇 | 下一篇

[UVA] 12527 - Different Digits

推薦 0 收藏 0 轉貼0 訂閱站台

The inhabitants of Nlogonia are very superstitious. One of their beliefs is that street house numbers that have a repeated digit bring bad luck for the residents. Therefore, they would never live in a house which has a street number like 838 or 1004.

The Queen of Nlogonia ordered a new seaside avenue to be built, and wants to assign to the new houses only numbers without repeated digits, to avoid discomfort among her subjects. You have been appointed by Her Majesty to write a program that, given two integers N and M, determines the maximum number of houses that can be assigned street numbers between N and M, inclusive, that do not have repeated digits.

Input 

Each test case is described using one line. The line contains two integers N and M, as described above ( 1$ le$N$ le$M$ le$5000).

Output 

For each test case output a line with an integer representing the number of street house numbers between N and M, inclusive, with no repeated digits.

Sample Input 

87 104
989 1022
22 25
1234 1234

Sample Output 

14
0
3
1

#include <stdio.h>

int main() {
    int n, m;
    int ok[5001] = {};
    for(n = 1; n <= 5000; n++) {
        char used[10] = {};
        m = n;
        while(m) {
            if(used[m%10])  break;
            used[m%10] = 1;
            m /= 10;
        }
        if(m == 0)  ok[n] = 1;
        ok[n] += ok[n-1];
    }
    while(scanf("%d %d", &n, &m) == 2) {
        printf("%d\n", ok[m]-ok[n-1]);
    }
    return 0;
}

台長: Morris
人氣(1,381) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][dp] 526 - String Distance and Transform Process
此分類上一篇:[UVA][math] 12517 - Digit Sum

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文