思路:
.....设置三个数组分别为str、a、temp分别存放输入数据、判断标记、每列最大值。首先通过纵向对比确定每列的最大值temp。然后再与原数组比较,将确定为最大值的元素位置标记为1。最后遍历标记数组,每行出现‘1’时计数变量加一,并且开始遍历下一行直至遍历结束。
代码如下:
#include<bits/stdc++.h> using namespace std; char str[100][100]; int a[100][100]={0}; int temp[100]={0}; int main() { int n=0,m=0,count=0; scanf("%d%d",&n,&m); getchar(); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) scanf("%c",&str[i][j]); getchar(); } for(int i=0,j=0;j<m;j++) { while(i<n) { if(str[i][j]>=temp[j])temp[j]=str[i][j]; i++; } i=0; } for(int i=0,j=0;j<m;j++) { while(i<n) { if(str[i][j]==temp[j])a[i][j]=1; i++; }i=0; } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(a[i][j]==1) { count++;break; } } } printf("%d",count); return 0; }
复杂度是O(n*m),大家有什么意见可以提出来一起交流。