彩笔
2022-05-25

代码本-数组入门

AcWing 数组的部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<cstdio>

int main() {
char t;
scanf("%c",&t);

double q[12][12]; // 初始化后全部读入
for (int i = 0;i < 12; i ++ )
for (int j = 0;j < 12; j ++ )
scanf("%lf",&q[i][j]);

double s = 0, c = 0;
for (int i = 1; i <= 5; i ++ )
for (int j = 0;j < #(i - 1)#;j ++ )
{
s += q[i][j];
c += 1;
}

for (int i = 6; i <= 10 ;i ++ )
for (int j = 0; j <= #(10 - i)#; j ++ )
{
s += q[i][j];
c += 1;
}

if ( t == 'S') printf ("%.1lf\n",s);
else printf("%.1lf\n", s / c );

return 0;
}