计算矩阵中以C ++降序排列的所有列
在本教程中,我们将讨论一个程序,以查找矩阵中以降序排列的列数。
为此,我们将提供一个矩阵。我们的任务是计算矩阵中具有按降序排列的元素的列数。
示例
#include <bits/stdc++.h>
#define MAX 100
using namespace std;
//计算按降序排列的列
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
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短