您的位置:首页 > 其它

读取条空比例

2015-12-29 10:56 369 查看
对于一组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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  条空比例