TopCoder problem "SpreadsheetColumn" used in SRM 261 (Division II Level One)



Problem Statement

    

Many spreadsheet applications use positive integers to label rows of cells and strings to label columns of cells. Your task is to write a function that gets the number of the column and returns its label.

All 26 uppercase letters are used to label the columns. Column labels are ordered according to their length, and labels with the same length are ordered in alphabetical order. Thus, the first 26 columns have a one-letter label, the following 26*26 columns have a two-letter label. The sequence of the labels looks as follows:

A, B, C, ..., Z, AA, AB, ..., AZ, BA, BB, ..., ZY, ZZ

The columns are numbered from 1, i.e., column number 1 has the label A.

 

Definition

    
Class:SpreadsheetColumn
Method:getLabel
Parameters:int
Returns:String
Method signature:String getLabel(int column)
(be sure your method is public)
    
 

Notes

-The constraints will guarantee that the column label is between "A" and "ZZ", inclusive
 

Constraints

-column will be between 1 and 702, inclusive.
 

Examples

0)
    
1
Returns: "A"
1)
    
2
Returns: "B"
2)
    
27
Returns: "AA"
3)
    
111
Returns: "DG"
4)
    
702
Returns: "ZZ"
Note that this is the largest possible input.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4651

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7995&pm=4651

Writer:

misof

Testers:

PabloGilberto , lbackstrom , brett1479 , Olexiy

Problem categories:

Simple Math, String Manipulation