Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的代码 晒晒#include <iostream> using namespace std; char s[5]; int main() { int tc; scanf("%d", &tc); gets(s); while (tc--) { gets(s); int sx, sy, ex, ey; sx = s[0]-'a' + 1, sy = s[1]-'0'; ex = s[3]-'a' + 1, ey = s[4]-'0'; int r1, r2, r3, r4; int t; t = min(abs(sx-ex), abs(sy-ey)); r1 = t + abs(sx-ex) - t + abs(sy-ey) - t; r2 = ((sx+sy)%2 == (ex+ey)%2 || sx == ex || sy == ey) ? 1 : 2; r3 = (sx == ex || sy == ey) ? 1 : 2; r4 = ((sx+sy)%2 == (ex+ey)%2) ? (abs(sx-ex) == abs(sy-ey) ? 1 : 2) : -1; (sx == ex && sy == ey) ? printf("0 0 0 0\n") : (r4 != -1 ? printf("%d %d %d %d\n", r1, r2, r3, r4) : printf("%d %d %d Inf\n", r1, r2, r3)); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator