Poj Solution 1657

http://poj.org/problem?id=1657

#include <stdio.h>
#include <math.h>
int main()
{
    int t;
    scanf("%d", &t);
 
    char c1, c2;
    int x1, y1, x2, y2;
    int w, h, c, x;
    while (t--)
    {
        getchar();
        scanf("%c%d %c%d", &c1, &y1, &c2, &y2);
        x1 = c1 - 'a' + 1;
        x2 = c2 - 'a' + 1;
 
        c1 = abs(x1 - x2);
        c2 = abs(y1 - y2);
 
        if (c1 + c2 == 0)
        {
            printf("0 0 0 0n");
        }
        else
        {
            if (c1 > c2) w = c1;
            else w = c2;
 
            if (c1 == c2 || x1 == x2 || y1 == y2) h = 1;
            else h = 2;
 
            if (x1 == x2 || y1 == y2) c = 1;
            else c = 2;
 
            if (c1 == c2) x = 1;
            else if ((c1 + c2) % 2 == 0) x = 2;
            else x = -1;
 
            printf("%d %d %d ", w, h, c);
            if (x >= 0)
            {
                printf("%dn", x);
            }
            else
            {
                printf("Infn");
            }
        }
    }
    //system("pause");
    return 0;
}
											
This entry was posted in poj. Bookmark the permalink.