Connection Status:
Competition Arena > Chessboard
SRM 344 · 2007-03-28 · by Petr · Simple Math
Class Name: Chessboard
Return Type: String
Method Name: changeNotation
Arg Types: (string)
Problem Statement

Problem Statement

A 8x8 chessboard is usually marked as follows: rows are marked by digits, 1 through 8, and columns are marked by letters, 'a' through 'h'. A cell is described by its column mark and then its row mark, like "e4".

While working on a chess program, you need to convert these descriptions into your internal cell numbers and back. Internally, cells are numbered row-by-row from 1 to 64 in your program, i.e., cell "a1" has number 1, cell "b1" has number 2, cell "c1" has number 3, ..., cell "h8" has number 64.

Given a String cell, describing either the cell mark or the cell number, change the notation (i.e., if you're given the mark you need to return the number, and vice versa).

Constraints

  • cell will contain either a cell mark or a cell number.
  • If cell contains a cell mark, it will contain exactly 2 characters: a lowercase letter between 'a' and 'h', inclusive, followed by a digit between '1' and '8', inclusive.
  • If cell contains a cell number, it will be an integer between 1 and 64, inclusive, without leading zeros.
Examples
0)
"1"
Returns: "a1"
1)
"2"
Returns: "b1"
2)
"3"
Returns: "c1"
3)
"4"
Returns: "d1"
4)
"5"
Returns: "e1"

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

Coding Area

Language: C++17 · define a public class Chessboard with a public method string changeNotation(string cell) · 150 test cases · 2 s / 256 MB per case

Submitting as anonymous