一个简易的求眼图高和宽的方法

#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#define ROW 10
#define COLS 10

int a[ROW][COLS] = {
                1,1,1,1,1,1,1,1,1,1,\
                1,1,1,1,0,1,1,1,1,1,\
                1,1,1,1,0,0,0,1,1,1,\
                1,1,1,1,0,0,0,1,1,1,\
                1,1,1,0,0,0,0,1,1,1,\
                1,1,1,0,0,0,0,1,1,1,\
                1,1,1,0,0,0,0,1,1,1,\
                1,1,1,1,0,0,0,1,1,1,\
                1,1,1,1,1,0,1,1,1,1,\
                1,1,1,1,1,1,1,1,1,1
                };


int main()
{
    int i;
    int j;
    int x = 10;
    int y = 10;
    int width;
    int height;
    char *pstart,*pend;

    char *p = malloc(x * y);
    if(p == NULL)
    {
        printf("malloc failed\n");
        return -1;
    }

    for(i = 0; i < x; i++)
    {
        for(j=0;j<y;j++)
        {
            if(a[i][j] == 1)
                *(p+i*y+j) = 0x31;
            else
                *(p+i*y+j) = 0x30;
        }
    }
    pstart = p + (x-1)/2 * y ;
    pstart = strstr(pstart,"111000");
    if(pstart == NULL)
        return -1;
    pstart = pstart + 3;
    pend = strstr(pstart,"000111");
    if(pend == NULL)
        return -1;
    pend = pend + 3;
    width = pend - pstart;
    printf("width:%d\n",width);

    char *pp = malloc(x * y);
    if(pp == NULL)
    {
        printf("malloc failed\n");
        return -1;
    }
    for (i = 0; i< x; i++)
    {
        for(j = 0; j< y; j++)
        {    
            *(pp + i * x + j) = *(p + j * y + i);
        }
    }

    for (i = 0; i< x; i++)
    {
        for(j = 0; j < y; j++)
        {    
            printf("%c ", *(pp + i * x + j));
        }
        printf("\n");
    }
    
    pstart = pp + (y-1)/2 * x ;
    pstart = strstr(pstart,"1000");
    if(pstart == NULL)
        return -1;
    pstart = pstart + 1;
    pend = strstr(pstart,"0001");
    if(pend == NULL)
        return -1;
    pend = pend + 3;
    height = pend - pstart;
    printf("height:%d\n", height);

    return 0;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值