Algorithm


Problem Name: beecrowd | 1181

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1181

Line in Array

 

By Neilor Tonin, URI Brazil

Timelimit: 1

Your job in this problem is to read a number that is a line of an array, an uppercase character, indicating the operation to be performed and all elements of a bidimentional array M[12][12]. Then, you have to calculate and print the sum or average of all elements within the green area according to the case. The following figure illustrates the case when is entered the number 2 to the array line, showing all elements that must be considered in the operation.


 

Input

 

The first line of the input contains a simple integer L (0 ≤ L ≤ 11) indicating the line to be considered in the operation. The second line of the input contains a single uppercase character T ('S' or 'M'), indicating the operation Sum or Average (Média in portuguese) to be performed with the elements of the array. Follow the 144 floating-point numbers of the array, considering that the elements are inserted line by line, from line 0 to line 11, always from left to right.

 

Output

 

Print the calculated result (sum or average), with one digit after the decimal point.

 

 

 

Input Sample Output Sample

2
S
1.0
-3.5
2.5
4.1
...

12.6

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
 
using namespace std;
 
int main() {
 
    float m[12][12];
    int index;
    char c;
    cin>>index;
    cin>>c;
    for(int i=0;i < 12;i++)
    {
        for(int j=0;j < 12;j++)
        {
            cin>>m[i][j];
        }
    }
    float sum=0.0;
    for(int i=0;i < 12;i++)
    {
        sum=sum+m[index][i];
    }
    if(c=='S')
    printf("%.1f\n",sum);
    if(c=='M')
    printf("%.1f\n",sum/12);
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 S 1.0 -3.5 2.5 4.1 ...

Output

x
+
cmd
12.6
Advertisements

Demonstration


Previous
#1180 Beecrowd Online Judge Solution 1180 Lowest Number and Position Solution in C++, Java, Js and Python
Next
#1182 Beecrowd Online Judge Solution 1182 Column in Array Solution in C++, Java, Js and Python