使用char型数组保存数据,记得getchar()吸收换行符,其次在进行大小比较时记得将char型数据转换为整型。
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
char a[110][110];
bool flag[110] = {false};
int maxNum[110] = {-1};
int main(){
int n, m;
cin >> n >> m;
getchar();
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
cin >> a[i][j];
}
getchar();
}
for(int i = 0; i < m; ++i){
for(int j = 0; j < n; ++j){
if((a[j][i] - '0') > maxNum[i]) maxNum[i] = (a[j][i] - '0');
}
}
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if(a[i][j] >= maxNum[j])flag[i] = true;
}
}
int cnt = 0;
for(int i = 0; i < n; ++i){
if(flag[i]) ++cnt;
}
cout << cnt;
return 0;
}


京公网安备 11010502036488号