文章

43

粉丝

180

获赞

82

访问

204.3k

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

  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int n, a[11][11], res[30];
  5. int main()
  6. {
  7. int n; cin >> n;
  8. for (int i = 1; i <= n; i ++ )
  9. for (int j = 1; j <= n; j ++ )
  10. cin >> a[i][j];
  11. int cnt = 0;
  12. for (int i = 1; i <= n; i ++ )
  13. {
  14. for (int j = 1; j <= n; j ++ ) res[cnt] += a[i][j];
  15. cnt ++;
  16. }
  17. for (int i = 1; i <= n; i ++ )
  18. {
  19. for (int j = 1; j <= n; j ++ ) res[cnt] += a[j][i];
  20. cnt ++;
  21. }
  22. for (int i = 1; i <= n; i ++ ) res[cnt] += a[i][i];
  23. cnt ++;
  24. for (int i = 1; i <= n; i ++ ) res[cnt] += a[i][n - i + 1];
  25. cnt ++;
  26. sort(res, res + cnt);
  27. for (int i = 0; i < cnt; i ++ ) cout << res[cnt - i - 1] << ' ';
  28. return 0;
  29. }

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发