(算法练习)——Problem B
程序员文章站
2024-03-22 17:37:52
...
要求:
http://codeup.cn/problem.php?cid=100000581&pid=4
说明:
这一题题目说只有一组数据就是假的!!依然要用while循环才能通过。。。不难,还是sort的用法,事实上一共是2*n+2个数据
代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int numrecord[30];
int record[11][11];
int main(){
int n;
while(scanf("%d",&n) != EOF){
int count = 0;
int liecount = 0;
int zhudjcount = 0;
int fudjcount = 0;
for(int i = 0;i <n;i++){
for(int j = 0;j <n;j++){
scanf("%d",&record[i][j]);
count = count + record[i][j];
}
numrecord[i] = count;
count = 0;
}
for(int i = 0;i <n;i++){
for(int j = 0;j <n;j++){
liecount = liecount + record[j][i];
}
numrecord[n+i] = liecount;
liecount = 0;
zhudjcount = zhudjcount + record[i][i];
fudjcount = fudjcount + record[i][n-1-i];
}
numrecord[n*2] = zhudjcount;
numrecord[n*2+1] = fudjcount;
sort(numrecord,numrecord+n*2+2);
for(int i = 2*n+1;i >=0;i--){
printf("%d",numrecord[i]);
if(i >0) printf(" ");
}
printf("\n");
}
}