Algorithm


Problem Name: beecrowd | 1184

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

Below the Main Diagonal

 

By Neilor Tonin, URI Brazil

Timelimit: 1

Read an uppercase character that indicates an operation that will be performed in an array M[12][12]. Then, calculate and print the sum or average considering only that numbers that are below of the main diagonal of the array, like shown in the following figure (green area).


 

Input

 

The first line of the input contains a single uppercase character O ('S' or 'M'), indicating the operation Sum or Average (Média in portuguese) to be performed with the elements of the array. Follow 144 floating-point numbers of the array.

 

Output

 

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

 

 

 

Input Sample Output Sample

S
5.0
0.0
-3.5
2.5
4.1
...

12.6

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>
using namespace std;

int main()
{
    double a[12][12];
    char c;
    cin >> c;
    double sum = 0;
    for(int i = 0 ; i  <  12; i++){
        for(int j = 0 ; j  <  12; j++){
            cin >> a[i][j];
        }
    }
    int u = 0;
    for(int i = 0 ; i  <  12; i++){
        for(int j = 0 ; j  <  u; j++){
            sum += a[i][j];
        }
        u++;

    }
    if(c == 'S') printf("%.1f\n" , sum);
    else if(c == 'M') printf("%.1f\n" , sum/66);


    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
S 5.0 0.0 -3.5 2.5 4.1 ...

Output

x
+
cmd
12.6
Advertisements

Demonstration


Previous
#1183 Beecrowd Online Judge Solution 1183 Above the Main Diagonal Solution in C++, Java, Js and Python
Next
#1185 Beecrowd Online Judge Solution 1185 Above the Secundary Diagonal Solution in C++, Java, Js and Python