Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<conio.h>
- int main()
- {
- int F,B,BD,FD,T,N,cpos=0,npos=0,time=0,flag=0,disp=0,i,j;
- int tests[100][5];
- scanf("%d",&N);
- for(i=0;i<N;i++)
- {
- for(j=0;j<5;j++)
- {
- scanf("%d",&(tests[i][j]));
- }
- }
- for(i=0;i<N;i++)
- {
- F=tests[i][0];
- B=tests[i][1];
- T=tests[i][2];
- FD=tests[i][3];
- BD=tests[i][4];
- time=0;
- disp=0;
- cpos=0;
- npos=0;
- flag=0;
- if(F==B)
- {
- cpos=F;
- if(FD<=cpos)
- {
- time= time+FD*T;
- printf("%d F\n",time);
- }
- else if(BD<=cpos)
- {
- time=time+BD*T+F*T;
- printf("%d B\n",time);
- }
- else
- {
- printf("No Ditch\n");
- }
- }
- else
- {
- while(flag==0)
- {
- npos=cpos+F;
- if(cpos<FD && FD <=npos)
- {
- disp=FD-cpos;
- time=time+disp*T;
- printf("%d F\n",time);
- flag=1;
- }
- time=time+F*T;
- cpos=npos-B;
- if(BD<=abs(cpos) && abs(npos)<BD)
- {
- disp=BD-abs(npos);
- time=time+disp*T;
- printf("%d B\n",time);
- flag=1;
- }
- time=time+B*T;
- }
- }
- }
- getch();
- return -1;
- }
Add Comment
Please, Sign In to add comment