| ||||||||||
| 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 | |||||||||
大哥大姐,帮我看一下。Thank you!!!Source
#include <iostream.h>
#include <math.h>
struct position
{ char line;
int row;
}startingPosition[20],arrivingPosition[20];
void main()
{ int t,line[20],row[20]; //测试数据的组数
cout<<"Please input the number of the items checked"<<endl;
cin>>t;
for(int i=1;i<=t;i++)
{ cout<<"Please input the line and the row of the starting place of the "<<i<<"th item"<<endl;
cin>>startingPosition[i].line>>startingPosition[i].row;
cout<<"Please input the line and the row of the destination of the "<<i<<"th item"<<endl;
cin>>arrivingPosition[i].line>>arrivingPosition[i].row;
line[i]=fabs(startingPosition[i].line-arrivingPosition[i].line);
row[i]=fabs(startingPosition[i].row-arrivingPosition[i].row);
int j=line[i]<row[i]? line[i]:row[i];
cout<<"For the king,the least steps is "<<j+fabs(line[i]-row[i])<<endl;
if(line[i]==row[i]||line[i]==0||row[i]==0)
cout<<"For the queen,the least steps is 1"<<endl;
else
cout<<"For the queen,the least steps is 2"<<endl;
if(line[i]==0||row[i]==0)
cout<<"For the cart,the least steps is 1"<<endl;
else
cout<<"For the cart,the least steps is 2"<<endl;
if(line[i]==row[i])
cout<<"For the elephant,the least steps is 1"<<endl;
else
cout<<"For the elephant,it is Inf"<<endl;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator