2013-12-05 16:30:06Morris

[UVA][Easy] 12658 - Character Recognition

Write a program that recognizes characters. Don't worry, because you only need to recognize three
digits: 1, 2 and 3. Here they are:

.*. *** ***
.*. ..* ..*
.*. *** ***
.*. *.. ..*
.*. *** ***

SampleInput

3
.*..***.***.
.*....*...*.
.*..***.***.
.*..*.....*.
.*..***.***.

SampleOutput

123


只有123需要判別,單獨看第四行即可判別,星號剛好錯開。

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

int main() {
    int n, i, j;
    char s[1024];
    while(scanf("%d", &n) == 1) {
        scanf("%*s");
        scanf("%*s");
        scanf("%*s");
        scanf("%s", s);
        scanf("%*s");
        for(i = 0, j = 0; j < n; i += 4, j++) {
            if(s[i] == '*')
                putchar('2');
            else if(s[i+1] == '*')
                putchar('1');
            else
                putchar('3');
        }
        puts("");
    }
    return 0;
}