URI Online Judge Solution 1190 Right Area Using C, Python Programming Language.
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 included in the right area (green area) of this array, like shown in the following figure.
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.
OutputPrint the calculated result (sum or average), with one digit after the decimal point.
Input Sample | Output Sample |
S | 122.2 |
Solution Using C:
#include <stdio.h>
int main()
{
double a=0.0, M[12][12];
char T[2];
int x,y;
scanf("%s", &T);
for(x=0;x<=11;x++)
{
for(y=0; y<=11; y++)
{
scanf("%lf", &M[x][y]);
}
}
for(x=1; x<6; x++)
{
for(y=11; y>11-x; y--)
a += M[x][y];
}
for(x=6; x<11; x++)
{
for(y=x+1; y<12; y++)
a += M[x][y];
}
if(T[0]=='S')
printf("%.1lf\n",a);
else if(T[0]=='M')
{
a=a/30.0;
printf("%.1lf\n",a);
}
return 0;
}
Comments
Post a Comment