Assignment 2:
The task is to develop a program to convert spreadsheet cell names into the corresponding integer indices.
Spreadsheets (such as MS Excel or OO Calc) usually address cells using character and number codes. Characters are used for column whereas numbers refer to the row. A sample is cell A6 - first column, row #6. Row numbers are ordinary integers, column names are a bit tricky. After single letters A to Z, there is column AA, AB, ..., ZZ, AAA, AAB, ..., ZZZ, and so on, until a certain spreadsheet internal limit. Your program shall read the codes and convert them into the corresponding integer indices (to address an array, for instance).
The input of the program is a sequence of cell names, each on an input line. Your program shall read the input lines and decode the names. The reading of the input shall finish when the end of file is reached (EOF is active for the standard input).
The output is the pair of indices converted from the cell name (see sample below). The first index corresponds to the row, the second to the column. Caution, both row and column indices are counted from 0. Thus, cell A0 corresponds to indices [0,0]. Please note that indices are positive or zero. One output line shall be printed for each input line. Each output line must be followed by a newline.
The program must validate input data. If the input line is an invalid cell name, the program must detect it, display an error message (see below) and proceed to the next input line. The correct input format consists of:
mandatory column name formed by uppercase letters A to Z, without any spaces or other separators,
mandatory row name in the form of an integer, without spaces or any other separators,
there are no further characters following the row index,
an input line is usually terminated by a newline. The only exception is the last line in the input which may, but does not have to be terminated by the newline.
Please strictly adhere the format of the output. The output must exactly match the output of the reference program. The comparison is done by a machine, the machine requires an exact match. If your program provides output different from the reference, the program is considered malfunctioning. Be very careful, the machine is sensitive event to white space characters (spaces, newlines, tabulators). Please note that all output lines are followed by a newline character (
). This applies even to the last line of the output, moreover, this applies even to the error message. Download the enclosed archive. The archive contains a set of testing inputs and the expected outputs. Read Progtest FAQ to learn how to use input/output redirection and how to simplify testing of your programs.
Advices:
Read the input character-by-character. Use either scanf function with format %c, or getchar function to read the characters.
It is convenient to use the enclosed sample input data and input redirection to test this homework.
The indices start from 0. Thus, column A is converted into index 0.
The indices are not negative. Next, the input data do not fit into the range provided by int data type. On the other hand, unsigned int is sufficient.
Sample program runs:
Cell:
A5
= [5,0]
Z8
= [8,25]
AAA2345
= [2345,702]
PA12
= [12,416]
Cell:
AC23
= [23,28]
NBFA349
= [349,247572]
Cell:
a8
Invalid cell.
FIT
Invalid cell.
12345
Invalid cell.
A8B
Invalid cell.
A B3
Invalid cell.
Invalid cell.
GET ANSWERS / LIVE CHAT