this is it.
if you need an explanation ...beg.
Code:
#include <time.h>
#include <stdio.h>
//#include <conio>
////////////////////////////////////////////////////////////////////////////////
// ANDREW HALL a.k.a Kodeci //
// icymint3@yahoo.com | icymint3@gmail.com | alphanexxus@yahoo.com //
////////////////////////////////////////////////////////////////////////////////
int main()
{
// Timing declarations
clock_t start, finish;
double elapsed_time;
// Input declarations
int size = 100; // the length of the number
char value[130] = "A"; // I have to make sure thre is a leading 'A'
FILE * stream = fopen( "input.txt", "r" );
// Get data
fscanf(stream, "%d %s", &size, &value[1] );
// Close the file
fclose(stream);
start = clock();
// MY CODE HERE
int count = 1, digitFrom, digitTo = -1, offsetTable[] = {1,1,1,1,1};
const char *pDigit = value;
// shorten the value to the first non 'A'
while( *++pDigit == 'A' ) size--;
// jump to the least significant digit
pDigit+= size;
// calculate until most significant digit is 0... 'A'
for( digitFrom = *--pDigit - 'A'; digitTo ; digitFrom = digitTo )
{
do
{
// normalize digit in [A,E] to [0,4]... and move ptr to next digit
digitTo = *--pDigit - 'A';
// update the offset table before moving to the next level
for( int sigma = 5 ; sigma-- ; ) // print if you not sure whats goin on
offsetTable[ sigma - 1 ]+= offsetTable[ sigma ] ;
}while( digitTo == digitFrom );
// predict how much numbers would be jumped fo such a move
count+= offsetTable[ digitTo ] - offsetTable[ digitFrom ];
// Have a look at what is going on
//gotoxy( 5,5);
//cprintf("%d %d %s\n", count,offsetTable[ digitTo ] - offsetTable[ digitFrom ],pDigit);
//getch();
}
// CODE ENDS
finish = clock();
printf("selcount = %d", count);
elapsed_time = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "\nProgram takes %3.4f seconds.\n", elapsed_time );
//getch();
return 1;
}