读取条空比例

来源:互联网 发布:长春绝命毒师网络比赛 编辑:程序博客网 时间:2024/05/07 05:08

对于一组01数据,计算它的宽度,以1为开头。

#include <iostream>using name space std;int main(){    int message[] = { 1, 1, 0, 0, 0, 1, 1, 1,  0, 0, 0, 0,                      1, 1, 1};    int size = sizeof(message) / sizeof(int);    int * countTransition = new int[size];    memset(countTransition, 0, sizeof(int)*size);    int currentState = 0;    for(int i = 0; i< size; i++)    {        if(message[i])        {            if((currentState & 1) == 1)                currentState ++;            countTransition[currentState] ++;        }        else        {            if((currentState & 1) == 0)                currentState ++;            countTransition[currentState] ++;        }    }    int num = currentState + 1;    for(int i = 0; i < num; i++)    {        cout << countTransition[i] << endl;    }    delete[]countTransition;    return 0;}
0 0