Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef vector<vector<int> > Matrix;
- // input : a matrix NxM, N>0, M>0, containing sorted rows of only 0's and 1's.
- // output: index (between 0 and N-1) of the first row with maximum number of 1's)
- int find_row_most_ones(const Matrix& M){
- int row=0,aux,max=0;
- for(int i=0;i<M.size();++i){
- aux=0;
- for(int j=0;j<M[0].size();++j){
- if(M[i][j]==1) ++aux;
- }
- if(aux>max){
- max=aux;
- row=i;
- }
- }
- return row;
- }
- int main(){
- int n,m;
- while(cin>>n){
- cin>>m;
- Matrix p(n,vector<int>(m));
- for(int i=0;i<n;++i){
- for(int j=0;j<m;++j) cin>>p[i][j];
- }
- cout<<"Row: "<<find_row_most_ones(p)<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement