【HDOJ】1197 Specialized Four-Digit Numbers

水题,暴力可解。

#include <iostream>

using namespace std;

int chg(int n, int base);

int main() {

    int i;
    int tmp;

    for (i=2992; i<10000; i++) {
        tmp = chg(i, 10);
        if ( tmp == chg(i, 16) && tmp == chg(i, 12) )
            cout <<i<<endl;
    }
}

int chg(int n, int base) {
    int sum = 0;

    while (n > 0) {
        sum += n % base;
        n = n / base;
    }

    return sum;
}

 

posted on 2014-02-28 21:58  Bombe  阅读(164)  评论(0编辑  收藏  举报

导航