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 |
怎么弄都是wrong answer,大虾帮忙啊1657那个象棋的题 #include <iostream.h> #include <math.h> void main(void) { int start1,start2,end1,end2,t,j,i=0,king_min=0,chariot_min,elephant_min=3,queen_min; char sourse[20][4]; bool b=0; while(cin>>t) { if(t==0) cout<<"0 0 0 0"<<endl; else{ for(i=0;i<t;i++){ for(j=0;j<4;j++) cin>>sourse[i][j]; } for(i=0;i<t;i++) { start1=sourse[i][0]-'a'+1; //得到起始、终了位置 start2=sourse[i][1]-'0'; end1=sourse[i][2]-'a'+1; end2=sourse[i][3]-'0'; //the king if(abs(start1-end1)>=abs(start2-end2)) king_min=abs(start1-end1); else king_min=abs(start2-end2); //the chariot if(start1==end1&&start2==end2) chariot_min=0; else if(start1==end1||start2==end2) chariot_min=1; else chariot_min=2; //elephant if((start1-end1)%2!=(start2-end2)%2) b=1; else if(start1==end1&&start2==end2) elephant_min=0; else if(abs(start1-end1)==abs(start2-end2)) elephant_min=1; else elephant_min=2; //the queen if(chariot_min<=elephant_min) queen_min=chariot_min; else queen_min=elephant_min; if(b==1) cout<<king_min<<" "<<queen_min<<" "<<chariot_min<<" Inf"<<endl; else cout<<king_min<<" "<<queen_min<<" "<<chariot_min<<" "<<elephant_min<<endl; b=0; } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator