64,682
社区成员
发帖
与我相关
我的任务
分享
static int32 brackets(char *values)
{
int32 counts[1000 / 3 + 2];
memset(counts, 0, sizeof(int32) * (1000 / 3 + 2));
int32 value = 0, left = 0, index = 0, right = 0;
counts[0] = -1;
for(char next = *values; next != 0; next = *++values)
{
if((next &= 1) == 0)
{
if(right == 1)
{
while(counts[index] >= left) --index;
counts[++index] = left;
}
++left;
right = 0;
}
else if(--left > 0) right = 1;
else if(left == 0)
{
index = 1;
right = 0;
counts[1] = 0;
}
else
{
value += index;
left = index = 0;
}
}
if(right == 1)
{
while(counts[index] >= left) --index;
++index;
}
return value + index;
}
memset(counts, 0, sizeof(int32) * (1000 / 3 + 2));
#include <stdio.h>
#include <stdio.h>