NxM 크기의 배열이 주어지고 N개의 행과 M개의 열이 주어지고 모든 열에 있는 0의 수를 기반으로 정렬 작업을 수행한 후 해당 행렬의 모든 열에 있는 0의 수를 인쇄하는 작업이 수행됩니다.
예를 들어 1 st 열에는 1개의 0과 2개의 nd 가 포함됩니다. 열에 0과 3 rd 이 포함되지 않습니다. 열에 2개의 0이 포함된 경우 결과는 − 3 1 2여야 합니다.
예
Input: 0 0 0 1 1 1 1 0 1 Output: 1 3 2
설명

참고 - 행렬은 인덱스 1부터 시작되는 것으로 간주됩니다.
예
#include <bits/stdc++.h>
#define row 3
#define col 3
using namespace std;
void sorting(int arr[row][col]){
vector<pair<int, int> >count_zero;
for (int i = 0; i < col; i++){
int count = 0;
for (int j = 0; j < row; j++){
if (arr[j][i] == 0)
count++;
}
count_zero.push_back(make_pair(count, i));
}
sort(count_zero.begin(), count_zero.end());
for (int i = 0; i < col; i++)
cout<< count_zero[i].second + 1 << " ";
}
int main(){
int array[row][col] = {
{ 0, 0, 0 },
{ 1, 1, 1 },
{ 1, 0, 1 }
};
cout<<"sorted order of zeroes count is : ";
sorting(array);
return 0;
} 출력
위의 프로그램을 실행하면 다음 출력이 생성됩니다.
sorted order of zeroes count is : 1 3 2