Connection Status:
Competition Arena > SpreadsheetColumn
SRM 261 · 2005-08-30 · by misof · Simple Math, String Manipulation
Class Name: SpreadsheetColumn
Return Type: String
Method Name: getLabel
Arg Types: (int)
Problem Statement

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.

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.

Submissions are judged against all 90 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class SpreadsheetColumn with a public method string getLabel(int column) · 90 test cases · 2 s / 256 MB per case

Submitting as anonymous