TopcoderArchiveVisit Topcoder
SRM30 Aug 2005
SRM 261

SpreadsheetColumn

Problem statement, definition, constraints, and public examples.

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

  1. 1
    Returns: "A"
  2. 2
    Returns: "B"
  3. 27
    Returns: "AA"
  4. 111
    Returns: "DG"
  5. 702
    Returns: "ZZ"
    Note that this is the largest possible input.
Back to all problems