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<stdio.h> #include<math.h> int max(int a,int b){ return a>b?a:b; }; int main() { int n,flag,i; char str[100],str1[100]; int n1,n2,n3,n4; int dist1,dist2; scanf("%d",&n); for(i=1;i<=n;i++){ flag=0; scanf("%s %s",&str,&str1); dist1=abs(str[0]-str1[0]); dist2=abs(str[1]-str1[1]); if(dist1==0&&dist2==0) n1=n2=n3=n4=0; else if(dist1==dist2){ n1=dist1; n2=1; n3=2; n4=1; } else if(dist1==0&&dist2%2!=0){ n1=dist2; n2=1; n3=1; flag=1; } else if(dist1==0&&dist2%2==0){ n1=dist2; n2=1; n3=1; n4=2;; } else if(dist2==0&&dist1%2!=0){ n1=dist2; n2=1; n3=1; flag=1; } else if(dist2==0&&dist1==0){ n1=dist2; n2=1; n3=1; n4=2; } else if((dist1%2==0&&dist2%2==0)||(dist1%2!=0&&dist2%2!=0)){ n1=max(dist1,dist2); n2=2; n3=2; n4=2; } if(flag) printf("%d %d %d Inf\n",n1,n2,n3); else printf("%d %d %d %d\n",n1,n2,n3,n4); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator