Does any one have algorithm or logic to Convert A to 1 ,B to 2, ... ,Z to 26 and then ,AA to 27, AB to 28 and so on BUT BA or cb or cbe or any string which has letters in descending order should not be numbered a for eg: BB should be 53 as BA is not numbered .this question is very similar to Convert A to 1 B to 2 ... Z to 26 and then AA to 27 AB to 28 (column indexes to column references in Excel) but with a slight difference as mentioned above
Asked
Active
Viewed 114 times
0
-
1"A" is a string with letters in descending order. – Chris Martin Oct 03 '13 at 02:37
-
What language are you using? – Monty Wild Oct 03 '13 at 02:47
-
im ok with just d algorithm or a hint towards it,but java is what i would use – Kaushik Sivakumar Oct 03 '13 at 02:48
2 Answers
0
Assume your first character in cell A1 and second character in cell B1, the following formula should help you to calculate the value
=IF(ISBLANK(A1),0,CODE(A1)-CODE("A")+1)*26+(CODE(B1)-CODE("A")+1)
For only A to Z, A1 is blank and put the single character in B1.

Ken Cheung
- 1,778
- 14
- 13
-
i actually want to do it programatically and nt excel anyways ill see if your formula helps – Kaushik Sivakumar Oct 03 '13 at 02:46
0
I assume you want to have limited amount of mappings
Generate all mapping you want in order you need
A, B, C, ... , Z, AA, AB, ... ,AZ, BA, BB, ..., BZ
Filter mappings with letters in non-descending order
A, B, C, ... , AA, AB, ... ,AZ, BB, ..., BZ
(BA disappeared!)To check if the string is in non-descending order, just compare it to its sorted version.
Enumerate!

mishadoff
- 10,719
- 2
- 33
- 55