AcWing 745. 数组的右上半部分
原题链接
中等
作者:
王小强
,
2021-03-24 18:40:17
,
所有人可见
,
阅读 376
语法练习
#include <iostream>
#include <vector>
using namespace std;
char op;
int main(int argc, char** argv) {
cin >> op;
vector<vector<float>> grid(12, vector<float>(12));
for (int y = 0; y < 12; ++y)
for (int x = 0; x < 12; ++x) cin >> grid[y][x];
int cnt = 0;
float sum = 0.0;
for (int y = 0; y < 11; ++y)
for (int x = y + 1; x < 12; ++x) {
++cnt;
sum += grid[y][x];
}
if (op == 'M') printf("%.1f", sum / cnt);
else printf("%.1f", sum);
return 0;
}