题解 | #Problem B#
Problem B
https://www.nowcoder.com/practice/bcd4ec5971054997a1dc282067aa1d8b
#include <bits/stdc++.h> using namespace std; int main() { int n; while(cin>>n){ vector<int>v; int arr[n][n]; for(int i =0;i<n;i++) for(int j =0;j<n;j++) cin>>arr[i][j]; for(int i =0;i<n;i++){ int temp=0; for(int j =0;j<n;j++){ temp+=arr[i][j]; } v.push_back(temp); } for(int i =0;i<n;i++){ int temp=0; for(int j =0;j<n;j++){ temp+=arr[j][i]; } v.push_back(temp); } //主副对角线 int sum=0; for(int i =0;i<n;i++){ sum+=arr[i][i]; } v.push_back(sum); sum=0; for(int i =0;i<n;i++) sum+=arr[i][n-i-1]; v.push_back(sum); sort(v.rbegin(),v.rend()); for(auto a:v) cout<<a<<" "; cout<<endl; } } // 64 位输出请用 printf("%lld")
qd