数组
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double nums[15][15],sum=0,count=0;
char c;
cin >> c;
for (int i = 0; i < 12; i++){
for(int j =0;j < 12;j++){
cin >> nums[i][j];
}
}
int x =1;
for (int i = 0;i < 11;i++){
for (int j = x; j < 12; j++){
sum += nums[i][j];
count ++;
}
x++;
}
printf("%.1lf",c == 'S'? sum:sum/count);
return 0;
}
不用数组
int main()
{
double a,sum = 0;
char c;
cin >> c;
int count = 0;
for(int i = 0;i < 12;i++){
for(int j = 0;j < 12;j++){
cin >> a;
if(j-i>=1) {
sum += a;
count ++;
}
}
}
printf("%.1lf",c == 'S'? sum:sum/count);
return 0;
}