文章

43

粉丝

180

获赞

21

访问

195.1k

头像
c++
P1423 西安电子科技大学机试题
发布于2022年4月26日 18:09
阅读数 3.9k

#include <iostream>
#include <algorithm>

using namespace std;

int n, a[11][11], res[30];

int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= n; j ++ )
			cin >> a[i][j];
	
	int cnt = 0;
	for (int i = 1; i <= n; i ++ )
	{
		for (int j = 1; j <= n; j ++ ) res[cnt] += a[i][j];
		cnt ++;
	}
	for (int i = 1; i <= n; i ++ )
	{
		for (int j = 1; j <= n; j ++ ) res[cnt] += a[j][i];
		cnt ++;
	}
	for (int i = 1; i <= n; i ++ ) res[cnt] += a[i][i];
	cnt ++;
	
	for (int i = 1; i <= n; i ++ ) res[cnt] += a[i][n - i + 1];
	cnt ++;
	
	sort(res, res + cnt);
	
	for (int i = 0; i < cnt; i ++ ) cout << res[cnt - i - 1] << ' ';
	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发