OCR

1 篇文章 0 订阅
                                 OCR 

Optical Character Recognition (OCR) is one of the most famous fields of Artificial Intelligence. The main purpose of OCR is to recognize printed text (or handwriting) and convert it to the machine encoded-text. You may have seen similar applications in your smartphone: you use your camera to take a photo that contains text, then, the text is translated or saved in PDF, for example. In this problem we deal with a very limited case of OCR. You have a scanned character which is either ‘0’ (number zero) or ‘8’ (number eight) and you have to decide what number it is. The input will be an image that contains exactly one character (It is guaranteed that this character is either ‘0’ or ‘8’). The image has 2 colors: white (represented with dot ‘.’) and black (represented with asterisk ‘*’). For simplicity, the borders of the image are always white. It’s also guaranteed that black lines inside the image are either vertical or horizontal. So you may safely assume that the shapes of ‘0’ and ‘8’ inside the image are the same as their shapes in digital clocks. However, they might be stretched or not positioned in the center of the image.

Input
The first line will be the number of test cases T (T<100). Each test case starts with two positive integers (n,m) denoting the dimensions of the image. (n,m < 20). Each of the following n lines contains m values which represent the image.

Output
For each test case, print one line which contains the number of the test case, and the recognition result: ‘Zero’ or ‘Eight’. See the samples and follow the output format.

Example
Input
3
8 10
……….
..*
..
..
..*
..
..*
……….
6 10
……….
..*
..
..
..*
……….
10 7
…….
…….
…….
…….
..**.
.....
..**.
.....
..**.
…….
Output
Case 1: Eight
Case 2: Zero
Case 3: Eight

题意:判断给定图中,*围成的图形是0还是8;

思路:也是一个水题,只需要判断是不是有这样的点,它的上下左右中有三个,有的话就是8,没有就是0;

code:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f

int n,m;
char a[30][30];
int x[30];

int main()
{
    int t,tt = 0;
    scanf("%d",&t);
    while(t--)
    {
        memset(x,0,sizeof(x));
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
            scanf("%s",a[i]);
        int tot = 0;
        int t1 = 0,t2 = 0;
        for(int i=1;i<=n;i++)
         for(int j=1;j<=m;j++)
           if(a[i][j] == '*')
           {
               if(a[i+1][j]=='*') tot++;
               if(a[i-1][j]=='*') tot++;
               if(a[i][j+1]=='*') tot++;
               if(a[i][j-1]=='*') tot++;
               if(tot == 3) t1++;
               tot = 0;
           }
        if(!t1)
            printf("Case %d: Zero\n",++tt);
        else
            printf("Case %d: Eight\n",++tt);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值