
程序代码:
#include <stdio.h>
void count_chang( const int datas[][4], size_t length, size_t counts[] )
{
    for( size_t c=0; c!=sizeof(*datas)/sizeof(**datas); ++c )
    {
        counts[c] = 0;
        int state = +1;
        size_t n = 0;
        for( size_t r=0; r!=length; ++r )
        {
            if( datas[r][c] == state )
                n = 0;
            else
            {
                ++n;
                if( n == 3 )
                {
                    ++counts[c];
                    state = datas[r][c];
                    n = 0;
                }
            }
        }
    }
}
int main( void )
{
    int datas[][4] = { { +1, -1, -1, +1 }
                     , { +1, -1, -1, +1 }
                     , { -1, -1, -1, +1 }
                     , { -1, -1, +1, +1 }
                     , { -1, -1, +1, -1 }
                     , { -1, +1, +1, +1 }
                     , { +1, +1, +1, +1 }
                     , { +1, +1, -1, +1 }
                     , { -1, +1, -1, +1 }
                     , { -1, +1, -1, +1 }
                     , { -1, +1, -1, +1 }
                     , { -1, +1, -1, +1 } };
    size_t counts[ sizeof(*datas)/sizeof(**datas) ];
    count_chang( datas, sizeof(datas)/sizeof(*datas), counts );
    for( size_t i=0; i!=sizeof(counts)/sizeof(*counts); ++i )
        printf( "Coloumn %zu, statu change count: %zu\n", i+1, counts[i] );
    return 0;
}