Saturday, May 22, 2010

find the nth string in a file

Given a series A,B,C .......Z, AA, AB,AC,AD....AZ,BA,BB...BZ,CA....(Open excel sheet. The names of column represent the series). Given input as number 'n'. Output the 'n' th string of the series.


Simply convert 'n' to a base-26 number. Each digit maps to a letter.

void f(int n)
{
if(n == 0)
return;
f((n-1)/26);
printf("%c", ((n-1)%26+'A'));
}

No comments:

Post a Comment