题目描述如下
简单的遍历二维数组,这里又开了一个二维数组来保存每一行的状态,同时用max来记录最大是哪一行
难度算是签到题了
ac代码如下:
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+10;
#define int long long
int n,m;
int a[N][N],b[N][2];//b[N][1]记录最大行有几个1,感觉用二元组会好看点,但笔者太菜不会
void solve(){
int max=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(a[i][j]==1) b[i][1]++;
}
if(b[i][1]>b[max][1]) max=i;//细节严格大于,保证输出下标最小的行标
}
cout<<max+1<<" "<<b[max][1];
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
solve();
return 0;
}