#include <stdio.h> #include <stdlib.h> int test_main(int map[100][100]); #define MAX 100 int test_main(int map[MAX][MAX]){ for(int line=0;line<MAX;line++){ for(int i=MAX-1;i>=0;i--){ if(map[line][i]==0)continue; if(map[line][i]%2==1){ for(int l=i;l<MAX;l++) if(map[line][l]%2==0&&map[line][l]>map[line][i]) map[line][i]=0; } } for(int i=0;i<MAX;i++){ if(map[line][i]==0)continue; if(map[line][i]%2==0){ for(int l=i;l>=0;l--) if(map[line][l]%2==1&&map[line][l]>map[line][i]) map[line][i]=0; } } } int num=0; for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) if(map[i][j]!=0) num++; return num; } static void build_data(int map[100][100]) { for (int x = 0; x < 100; x++) { for (int y = 0; y < 100; y++) { int r = rand() % 30; map[x][y] = r <= 10 ? r : 0; } } } void main(void) { int map[100][100]; for (int l = 0; l < 10; l++) { build_data(map); printf("%d\n", test_main(map)); } }