All pastes #330876 Raw Edit

Untitled

public text v1 · immutable
#330876 ·published 2007-01-28 11:04 UTC
rendered paste body
#define MAX 10000
int divisors[MAX];

void buildDivisors(){
     for(int i = 1; i < MAX ; i ++){
             for(int j = i ; j < MAX ; j += i){
                   divisors[j] ++;
             }
     }
}

char inputStr[10];
int len;

int findAnswer(int curPos, int value){
    
    if(curPos == len){
             // cout << "Trying " << value << endl;
              return divisors[value];
    }
    
    value *= 10;
    
    if( inputStr[curPos] != 'X'){
        value += (inputStr[curPos] - '0');
        return findAnswer( curPos + 1 , value );
    }
    
    int startDigit = (curPos == 0)  ? 1 : 0 ; 
    int maxDivisors = 0;
    int curDivisor;
    int curValue;
    
    for(int digit = startDigit; digit < 10 ; digit ++){
         curValue = value + digit;
         curDivisor = findAnswer ( curPos + 1 , curValue );
         maxDivisors = max( maxDivisors, curDivisor);
    }   
    return maxDivisors;   
}

int main(){
    int total;
    buildDivisors();
    cin >> total;

    while(total --){
                scanf("%s", inputStr);
                len = strlen(inputStr);               
                               
                cout << findAnswer( 0 , 0) << endl;
    }    
    return 0;
}