ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อค้นหาจำนวนคอลัมน์ในเมทริกซ์ที่จัดเรียงจากมากไปน้อย
สำหรับสิ่งนี้เราจะได้รับเมทริกซ์ งานของเราคือนับจำนวนคอลัมน์ในเมทริกซ์ที่มีองค์ประกอบเรียงตามลำดับจากมากไปน้อย
ตัวอย่าง
#include <bits/stdc++.h>
#define MAX 100
using namespace std;
//counting columns sorted in descending order
int count_dcolumns(int mat[][MAX], int r, int c){
int result = 0;
for (int i=0; i<c; i++){
int j;
for (j=r-1; j>0; j--)
if (mat[i][j-1] >= mat[i][j])
break;
if (c > 1 && j == 0)
result++;
}
return result;
}
int main(){
int m = 2, n = 2;
int mat[][MAX] = {{1, 3}, {0, 2,}};
cout << count_dcolumns(mat, m, n);
return 0;
} ผลลัพธ์
2