Created
January 26, 2012 16:37
-
-
Save Santarh/1683681 to your computer and use it in GitHub Desktop.
Excel Column Name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#define AtoZ 26 | |
#define ASCII_A 65 | |
int calc( char* c, int* sum ) | |
{ | |
if ( *c == '\0' ) | |
{ | |
return 0; | |
} | |
int digit = calc( c + 1, sum ); | |
int a = (int)*c - ASCII_A + 1; | |
*sum += a * pow( AtoZ, digit ); | |
return digit + 1; | |
} | |
int main( int argc, char* argv[] ) | |
{ | |
char* row = argv[ 1 ]; | |
int result = 0; | |
calc( row, &result ); | |
printf( "%d\n", result ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int calc( char* c, int sum ) | |
{ | |
if ( *c == '\0' ) | |
{ | |
return sum; | |
} | |
int a_to_z = 'Z' - 'A' + 1; | |
int now_digit = (int)*c - 'A' + 1; | |
return calc( c + 1, sum * a_to_z + now_digit ); | |
} | |
int main( int argc, char* argv[] ) | |
{ | |
printf( "%d\n", calc( argv[ 1 ], 0 ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment