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 <string.h> #include <math.h> int main() { int cases=0; int n1=0; char inf[4]={'\0'}; int king=0;//王所需要走的步数 int queen=0; int car=0; int elephant=0; int dx=0,dy=0; scanf("%d",&cases); getchar(); for(;n1<cases;n1++) { scanf("%c%c %c%c",inf,inf+1,inf+2,inf+3); getchar(); /* putchar(inf[0]); putchar(inf[1]); putchar(inf[2]); putchar(inf[3]); */ dx=abs(inf[2]-inf[0]); dy=abs(inf[3]-inf[1]); if((dx==0)&&(dy==0)) { printf("0 0 0 0\n"); continue; }//起始位置跟终止位置相同的情况 //王 king= (dx>dy)?dx:dy; //王后 if((dx==dy)||(dx==0)||(dy==0)) { queen=1; } else queen=2; //车 if((dx==0)||(dy==0)) { car=1; } else { car=2; } printf("%d %d %d ",king,queen,car); //象 if(abs(dx-dy)%2!=0) { printf("Inf\n"); } else if(dx==dy) { printf("1\n"); } else { printf("2\n"); } } return 0; } 注意两点 首先是象能走全部的黑格 白格不能走 然后 在相同的位置的时候 应该输出0 0 0 0 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator