Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的代码 晒晒

Posted by Be_the_top at 2010-07-24 16:12:57 on Problem 1657
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator