Mini-Spreadsheet

Given cells filled with functional formulas and data, display the calculated results of a mini–spreadsheet. Spreadsheet cells are labeled by columns (A...J) and rows (1...10). The cell in the 6-th column of the 3-rd row would be labeled with address F3. All cell entries will be integers. All function names and cell references are case insensitive. Any function not adhering to proper syntax should output ‘#SYN#’ in its cell. The functions the spreadsheet should handle are as follows: Average(Range) Calculate the average of the non-blank cells in a specified Range. Truncate result. Large(Range, k) Calculate the k-th largest distinct value of non-blank cells in a specified Range. k may be a cell address. Ex. Large(2,2,5,5,5,8,8,8,3) is 2. Output ‘#ERR#’ if impossible. Ex. Large(2,2,5,5,5,8,8,4) CountIF(Range, condition) Count the number of cells satisfying a condition. Conditions are “> n”, “< n”, “>= n”, “<= n”, or “= n”. n represents any integer. Positive numbers may have a leading ‘+’. Zero is a value; an empty cell, denoted by ‘B’, is not. Ex. CountIF(A4, B1:B5, “>0”) Median(Range) Find the median of the cells in a specified Range The median is the middle number of the cells if they are in numerical order. If the Range contains an odd number of cells, the median is the average of the two middle cells. Truncate the result if there is an even number of cells. Mode(Range) Find the mode of the cells in a specified Range The mode is the most frequently occurring value in the range. In case of a tie, use the first modal value occurring in a list of the Range values. Rectangular sections of the Range should be listed by rows, from left to right. SumIf(Evaluation Range, condition, Sum Range) Sum certain cells. If a cell in the Evaluation Range meets the specified condition, the corresponding cell in the Sum Range should be included in the sum. Output ‘#ERR#’ if there is not a 1-1 correspondence between Evaluation Range cells and Sum Range cells. Condition specifications are the same as those of the CountIf function. Rectangular sections of the Range are in row major form. That is, they should be listed by rows, from left to right. Any blank cell in the Evaluation Range counts for purposes of the required 1-1 correspondence, but the condition should automatically evaluate to False. Ex. If A1=1, A2=2, A4=4, B1=10, C1=20, B3=30, B4=40 SumIf(A1:A2, 3 ,A4, ”>2” , B1 , C1 ,B3:B4) is 70. A range may be a < Cell Address >, < Cell Address:Cell Address >, any integer, or a combi- nation of these separated by commas. Examples are ‘C5’, or ‘A3:B4’ (meaning A3, B3, A4, and B4), ‘55’, or the combination ‘D2, 55, A3:B4, J3’, respectively. There may be spaces within the parentheses. There will not be spaces separating a column and a row in a cell address.

2/2 Input The input file contains several test cases, each of them as described below. Input beginning with ‘R’ indicates a particular row’s data. Any row not accounted for should be filled with blanks. If a row is listed, all entries in the row are listed, from left to right, separated by blank(s). A row’s entries may extend over more than one line. There are no circular references in the data; however, one cell’s function may use another cell’s results as input. If there is an ‘#ERR#’ or ‘#SYN#’ in an input cell the function should display ‘#INP#’. If there is an ‘#INP#’ in any input cell the function should display ‘#INP#’. ‘#INP#’ is the error with most precedence. Two consecutive cases are separated by a blank line. Output For each test case, the output must follow the description below. Output should be exactly as the sample output shows. Column and row heading labels should be right justified in a field width of 5. All cells should be of width 5. Integers should be right-aligned within cells. Any cells without data should contain 5 spaces. There should be no extraneous spaces in the output, neither blank lines between different cases. Sample Input R1 8 4 5 7 B 4 3 6 90 B R3 7 8 11 14 Average(A3:D3,A3) SumF(A1 A2) B B B B R5 B 3 4 B B B B B B Large( B1:B10 , 3) R6 B 4 3 B B B B B B Average(4, J7) R7 B CountIf(B1:B6,">0") LARGE(C1:C6,D1:E6,1) B B BBB B Large(B1:B10, 5) R10 B Mode(A1:I1) Median(A1:I1,B1:B3) B B B B B B SUMIF(B5:C6,">3",A1:D1) Sample Output ABCDEFGHIJ 1 8 4 5 7 4 3 6 90 2 3 7 8 11 14 9#SYN# 4 5343 6 43 #INP# 7 4 14 #ERR# 8 9 1045 9