AcWing 748. 数组的右下半部分
原题链接
中等
作者:
wasd233
,
2024-03-05 19:16:05
,
所有人可见
,
阅读 32
C++
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
double M[12][12];
char x; cin >> x;
for (int i = 0; i < 12; i ++)
for (int j = 0; j < 12; j ++)
cin >> M[i][j];
double s = 0; int n = 0;
for (int i = 1; i < 12; i ++)
for (int j = 12 - i; j < 12; j ++)
{
s += M[i][j];
n ++;
}
if (x == 'S') printf("%.1lf\n", s);
else printf("%.1lf\n", s/n);
return 0;
}
Python
x = input()
M = []
for _ in range(12):
l = list(map(float, input().split()))
M.append(l)
s = 0
n = 0
for i in range(1, 12):
for j in range(12-i, 12):
s += M[i][j]
n += 1
if x == 'S':
print(f"{s:.1f}")
else:
print(f"{s/n:.1f}")