int main(void){ int F,B,T,FD,BD,tc,i,j; int RMove=0,RTime=0; scanf("%d",&tc); for(i=0;i<tc;i++){ scanf("%d %d %d %d %d",&F,&B,&T,&FD,&BD); int PMove=0,TTime=0; if(F==B) { if(F>FD) { printf("%d F\n",((FD*T))); } else printf("No Ditch\n"); return 0; } if(F>B) { RMove=F-B; RTime=(F+B)*T; Calculation(RMove,RTime,T,F,'F',FD,PMove,TTime); } else { RMove=B-F; RTime=(F+B)*T; Calculation(RMove,RTime,T,B,'B',BD,PMove,TTime); } } return 0; }
int Judge( NS * n,OS * o , char a[]) { float x,y,z; int i = 0; char sh; if(o->optop == Stack_Size - 1 ) { return FALSE; } sh = '#'; PushOperation(o,sh); while(a[i] != '#') {//全部进栈并且将所有操作全部转化,仅剩+ - if(a[i] >= 48 && a[i]<=57 ) { x = a[i] - 48; PushNum(n,x); } else if(a[i] == '+' && ( o->elem[o->optop - 1] == '*' || o->elem[o->optop - 1] == '/')) { PopNum(n,&x); PopNum(n,&y); PopOperation(o , &sh); z = Calculation( x, y , sh); PushNum(n , z); } else if(a[i] == '-' && (o->elem[o->optop - 1] == '*' || o->elem[o->optop - 1] == '/')) { PopNum(n,&x); PopNum(n,&y); PopOperation(o , &sh); z = Calculation( x, y , sh); PushNum(n , z); } else if( a[i] == '*' || a[i] == '/') { sh = a[i]; PopNum( n , &x); y = a[i+1] - 48; z = Calculation( x, y ,sh); PushNum(n,z); i++; } else { sh = a[i]; PushOperation(o , sh); } i++; } Result(n , o , a); return TRUE; }
void Lab1::on_btnStart_clicked() { GetSizeUAndUn(); SetUAndUn(); Calculation(); FilingResult(); }
int Result( NS * n , OS * o ,char a[]) { int flag = 1; float x = 0 , y = 0 , sum = 0; char sh; printf("%s = ",a); PopNum(n , &sum); while( n->numtop != -1 ) { PushOperation(o ,sh); PopNum(n , &x); sum = Calculation(sum,x,sh); } printf("%0.2f",sum); }
Calculation(int RMove,int RTime,int T,int StepTaken,char Direction,int DitchDistance,int PMove,int TTime){ if(PMove+StepTaken<DitchDistance && Direction=='F'){ TTime=TTime+RTime; PMove=PMove+RMove; } else if(PMove+StepTaken>=DitchDistance && Direction=='F'){ TTime=TTime+((DitchDistance-PMove)*T); PMove=PMove+((DitchDistance-PMove)); } else if(PMove+RMove<DitchDistance && Direction=='B'){ TTime=TTime+((DitchDistance/RMove)*RTime); DitchDistance=DitchDistance%RMove; PMove=PMove+(DitchDistance-(DitchDistance%StepTaken)); TTime=TTime+(StepTaken-(StepTaken-DitchDistance%StepTaken))*T; PMove=DitchDistance; } printf("%d %c\n",TTime,Direction); if(PMove<DitchDistance){Calculation(RMove,RTime,T,StepTaken,Direction,DitchDistance,PMove,TTime);} else {printf("%d %c\n",TTime,Direction);return;} }
double ParsingArithmeticExpressions::operator()(const char* str) { if (!stDou.IsEmpty()) stDou.Clear(); if (!stChar.IsEmpty()) stChar.Clear(); if (Expression != nullptr){ delete[] Expression; } RemovingGapsSyntaxChecking(str); Calculation(); double rez = 0.0; if (!stDou.IsEmpty()) rez = stDou.Pop(); return rez; }
void ParsingArithmeticExpressions::Calculation() { while (*myPtr) { if (*myPtr == ')'){ stChar.Push(*myPtr); --myPtr; Calculation(); } else if (*myPtr == '('){ --myPtr; break; } else if (TokenTypeNumber(*myPtr)){ Number(); if (!TokenTypeOperator(*myPtr)){ if (stChar.Peek() == ')') throw MyException("Ошибка. Между открывающей и закрывающей скобкой отсутствует выражение.", myPtr, Expression + 1); else throw MyException("Ошибка. Отсутствует выражение.", nullptr, Expression + 1); } } else if (*myPtr == '+' || *myPtr == '-'){ MultiplicationDivision(); stChar.Push(*myPtr); --myPtr; Number(); } else if (*myPtr == '*' || *myPtr == '/' || *myPtr == '^'){ stChar.Push(*myPtr); --myPtr; Number(); } } MultiplicationDivision(); AdditionSubtraction(); }
HRESULT ActionScene( int &asStage ) { //CParser CPrsr; HRESULT hr; D3DXMATRIX acMatrixView; pDirect3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 191, 245, 251 ), 1.0f, 0); pDirect3DDevice->BeginScene(); if( asStage == 10 ) { GetDInputAction(); Calculation(); ++ asStage; } if( asStage == 11 ) { D3DXMatrixLookAtLH(&acMatrixView, &D3DXVECTOR3( 0.0f, 40.0f, 0.f ), // определяет точку, из которой происходит просмотр сцены &D3DXVECTOR3(0.0f, 0.0f, 0.0001f), // определяет то на что мы смотрим &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); pDirect3DDevice->SetTransform( D3DTS_VIEW, &acMatrixView ); if( Start() ) { GetDInputAction(); if( s_start ) { ++ asStage; } } RenderScene(); } //Движение согласно XML if( asStage == 12 ) { GetDInputAction(); if( first ) { CPrsr.InitCarList(); Mesh *a; Mesh *b; Mesh *c; Mesh *d; for( int i = 0; i < 4; ++ i) { a = *(CPrsr.iteratorList); CPrsr.Iteration(); b = *(CPrsr.iteratorList); CPrsr.Iteration(); c = *(CPrsr.iteratorList); CPrsr.Iteration(); d = *(CPrsr.iteratorList); hr = CPrsr.YourTurn( a, b, c, d ); if( hr == S_OK ) a->ICanGo = true; else if( hr == S_FALSE ) MessageBox( NULL, L"Нет машин, проезжающих перекресток", L"End", MB_OK ); CPrsr.Iteration(); CPrsr.Iteration(); first = false; } } CPrsr.MoveCars(); RenderScene2(); } pDirect3DDevice->EndScene(); pDirect3DDevice->Present( NULL, NULL, NULL, NULL ); return S_OK; }