[algogeeks] Excel Sheet Question Asked

2011-02-01 Thread bittu
Given a series A,B,C ...Z, AA, AB,AC,ADAZ,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.  also
vice versa if given string prints its corresponding string...e.g given
AC then its integer is 29  given 40774 its string value is ABZ..



Thanks
Shashank

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Excel Sheet Question Asked

2011-02-01 Thread albert theboss
Simply L division by 26 gives the answer ...
like decimal to binary conversion thats it

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Excel Sheet Question Asked

2011-02-01 Thread Srikar
since the problem uses all 26 letters, we could use a number system with
base as 26. 2 operations are -

1) Given number to string - Treat the number as number in base 26.
2) Given string to number.

Credit goes here -
http://geeksforgeeks.org/forum/topic/amazon-interview-question-for-software-engineerdeveloper-fresher-about-algorithms-data-structure-strings



On Tue, Feb 1, 2011 at 6:27 PM, bittu shashank7andr...@gmail.com wrote:

 Given a series A,B,C ...Z, AA, AB,AC,ADAZ,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.  also
 vice versa if given string prints its corresponding string...e.g given
 AC then its integer is 29  given 40774 its string value is ABZ..



 Thanks
 Shashank

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Excel Sheet Question Asked

2011-02-01 Thread Wei.QI
@albert, You need to becareful when doing the divide, because there is no
ZERO. (Z - AA not Z-A0).
here is the code:

public static String ExcelMapIntToStr(int n)
{
 StringBuilder sb = new StringBuilder();
 while(n0)
 {
  sb.append((char)(('A' - 1) + (n-1)%26 + 1));
  n = (n-1)/26;
 }
 return sb.reverse().toString();
}

public static int ExcelMapStrToInt(String str)
{
 int val = 0;
 int base = 1;
 for(int i = str.length() - 1; i=0; i--)
 {
  val += (str.charAt(i) - ('A' - 1))*base;
  base *= 26;
 }
 return val;
}

On Tue, Feb 1, 2011 at 10:39 AM, albert theboss alberttheb...@gmail.comwrote:

 Simply L division by 26 gives the answer ...
 like decimal to binary conversion thats it

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Excel Sheet Question Asked

2011-02-01 Thread albert theboss
yes yes i forgot to say

when n is 26 we ll get (26)0 ie A0

so wen u encounter 0 u need to borrow one which ll become 26 for the
borrower number from previous number

so it ll become 0Z.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.