Wednesday, 4 July 2012

WAP to return numbered index if input is excel sheet column header name. e.g excel sheet column headers are A, B, C , D ... Z, AA, AB...AZ, BA,, etc if Input is D , output should be 4 and for AA output should be 27

// TIME : O(n)

#include<stdio.h> #include<string.h> int main() { int i=0,l,x,index=0; char S[5]; printf("Enter Column header : "); gets(S); l=strlen(S); while(i<l) { x=S[i++]-'A'+1; index=index*26+x; } printf("%d",index); return 0; }

No comments:

Post a Comment