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 |
Re:各位同学请帮我看一下,什么地方出了问题In Reply To:各位同学请帮我看一下,什么地方出了问题 Posted by:apolor at 2004-05-15 14:47:34 > #include<iostream.h> > #include<math.h> > > void main(){ > char x[20][8],y[20][8]; > int n,i,ax,ay; > cin>>n; > for(i=0;i<n;i++) > cin>>x[i]>>y[i]; > for(i=0;i<n;i++){ > ax=abs(x[i][0]-y[i][0]); > ay=abs(x[i][1]-y[i][1]); > if(ax>ay) > cout<<ax<<" "; > else cout<<ay<<" "; > > if(ax==ay||ax==0||ay==0) > cout<<"1 "; > else cout<<abs(ax-ay)+1<<" "; > > if(ax==0||ay==0) > cout<<"1 "; > else cout<<"2 "; > > if(ax==ay) > cout<<"1 "<<endl; > else cout<<"Inf "<<endl; > } > } > > 提交市老是出错,是算法有问题吗?或是还有别的什么地方没有考虑到。 算法错了,看下面的: #include<iostream.h> #include<math.h> void main(){ char x[25][8],y[25][8]; int n,i,ax,ay; cin>>n; for(i=0;i<n;i++) cin>>x[i]>>y[i]; for(i=0;i<n;i++){ ax=abs(x[i][0]-y[i][0]); ay=abs(x[i][1]-y[i][1]); if(ax>ay) cout<<ax<<" "; else cout<<ay<<" "; if(ax==ay||ax==0||ay==0) cout<<"1 "; else cout<<"2 "; if(ax==0||ay==0) cout<<"1 "; else cout<<"2 "; if((ax+ay)%2==0) if(ax==ay) cout<<"1 "<<endl; else cout<<"2 "<<endl; else cout<<"Inf "<<endl; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator