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 |
不好意思,本人没帮你解决问题,还给你增添了麻烦,这是我的程序(C++版)In Reply To:有一小子非说他的程序没错,要起诉北大.我觉得他挺可怜的,但我也找不出错.哪位大哥来帮看看.(C语言) Posted by:20054959 at 2007-01-16 21:09:55 不好意思,本人没帮你解决问题,还给你增添了麻烦 #include<iostream> const long MaxXY=2000000000; const long MaxVAB=2000000000; const long MaxL=2100000000; bool isMeet(long x,long y,long VA,long VB,long L,long &t); /*判断能否相见,如果能,用t返回相见时跳的次数*/ using namespace std; void main() { long x,y,VA,VB,L,N; cout<<"输入青蛙A和青蛙B位置x,y,速度VA,VB和纬线总长L,以第一个数目非法时结束"<<endl; if(!(cin>>x))return; while(x>=0&&x<=MaxXY) { if(!(cin>>y>>VA>>VB>>L))return; if(y<0||x==y||y>MaxXY||VA<0||VA>MaxVAB||VB<0||VB>MaxVAB||L<0||L<=x||L<=y||L>MaxL)//判断输入 cout<<"错误!请重新输入!"<<endl; else { if(isMeet(x,y,VA,VB,L,N))cout<<"这两只青蛙会见面的,见面时他们跳了"<<N<<"次"<<endl; else cout<<"很遗憾,他们这样不可能见面的!"<<endl; } cout<<"输入青蛙A和青蛙B位置x,y,速度VA,VB和纬线总长L,以第一个数目非法时结束"<<endl; if(!(cin>>x))return; } } bool isMeet(long x,long y,long VA,long VB,long L,long &N)/*判断能否相见,如果能,用t返回相见时跳的次数*/ { N=L; for(int i=1;i<N;i++) if(((VA-VB)*i+(x-y))%L==0) {N=i;break;} if(N!=L)return true; return false; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator