编程介的小学生 2019-06-13 19:56 采纳率: 0.4%
浏览 193

弱的数字识别的问题,用ascii studio的数字怎么识别,采用C语言的实现的方式是什么

Problem Description
Wiskey wants to develop an image retrieval system, but he can’t deal with the number recognition.

The number is neat which no any aliasing, no any redundant point, and made by ‘#’.
You can use the software “ASCII Art Studio”, the data come from there.

The font is Arial, and the font size between “五号” and “一号", the style is bold.
The data is weak, not all of the numbers which various sizes are need to be recognized.
Come on baby; please improve your program as much as possible.

Input
First line will contain one integer mean how many cases will follow by.
In each case will contain two integers N, M mean the N*M matrix will follow. (10 <= N, M <= 26)

Output
Print which number did you recognized.

Sample Input
2
10 7
###

#####

#####
###

14 9
#####

#######

### ###
#####

#####

### ###

#######
#####

Sample Output
0
8

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-10 08:20
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    这是一个简单的C程序,它使用了ASCII艺术生成器的数据来识别图像中的数字。程序首先读取输入数据,并将每个数字从图像中提取出来。然后,它将这些数字转换为字符串并打印到屏幕上。

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main() {
        int cases;
        scanf("%d", &cases);
    
        for (int i = 0; i < cases; i++) {
            int rows, cols;
            scanf("%d %d", &rows, &cols);
            char *matrix;
    
            // Generate ASCII art matrix
            matrix = (char *) malloc(rows * cols * sizeof(char));
            generate_ascii_art(matrix, rows, cols);
    
            // Extract digits from the matrix
            int num_digits = extract_digits(matrix, rows, cols);
    
            // Convert digits to string and print them
            printf("Digits: ");
            for (int j = 0; j < num_digits; j++) {
                printf("%d ", matrix[j]);
            }
            printf("\n");
        }
    
        free(matrix); // Free memory allocated for matrix
        return 0;
    }
    
    void generate_ascii_art(char *matrix, int rows, int cols) {
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (i == 0 || j == 0 || i == rows - 1 || j == cols - 1) {
                    matrix[i*cols + j] = '#';
                } else {
                    matrix[i*cols + j] = ' ';
                }
            }
        }
    }
    
    int extract_digits(char *matrix, int rows, int cols) {
        int num_digits = 0;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                if (matrix[i*cols + j] != '#' && matrix[i*cols + j] != ' ') {
                    num_digits++;
                }
            }
        }
        return num_digits;
    }
    

    这个程序首先定义了一个generate_ascii_art函数,用于生成ASCII艺术矩阵。然后是extract_digits函数,用于提取数字字符。最后,在主函数中,我们读取输入数据,生成矩阵,提取数字,打印结果。

    注意:这个程序没有进行任何错误检查和处理,例如边缘情况(如空行或列)以及不正确的输入等。在实际应用中,你可能需要添加更多的错误处理逻辑。

    评论

报告相同问题?