void pop() { if (s_1.empty()) { transfere(); } s_1.pop(); }
int main() { int n; char ch; while(cin>>n) { int i,j,k=0; arry[0]=n; ch=getchar(); while(ch!='\n') { cin>>arry[++k]; ch=getchar(); } k++; int flag=1,s; for(i=0;i<k;i++) { if(arry[i]<0) { team1.push(arry[i]); team2.push(arry[i]*(-1)); } else if(arry[i]>0) { if(team2.empty()) { flag=0; break; } if(arry[i]!=team2.top()) { flag=0; break; } else { team2.pop(); s=0; while(team1.top()>0) { s=s+team1.top(); team1.pop(); } if(s>=arry[i]) { flag=0; break; } team1.pop(); team1.push(arry[i]); } } } if(!team2.empty()) flag=0; if(flag) cout<<":-) Matrioshka!"<<endl; else cout<<":-( Try again."<<endl; while(!team1.empty()) team1.pop(); while(!team2.empty()) team2.pop(); } return 0; }
int getmin(void){ if (s1.empty() || s2.empty()) return s1.empty()?s2.top().second:s1.top().second; return min(s1.top().second,s2.top().second); }
void ejecutar(list<Instruccion*> *codigo) { list<Instruccion *>::iterator it = codigo->begin(); Instruccion *ri; RObject *arg1, *arg2, *arg3; bool set_tmp, fin_error=false; do { ri = *it++; arg1 = ri->arg1; arg2 = ri->arg2; arg3 = ri->arg3; if (arg1 != NULL && arg1->type == RVARIABLE) arg1 = get_variable(((RVariable*)arg1)->getValue()->data()); if (arg2 != NULL && arg2->type == RVARIABLE) arg2 = get_variable(((RVariable*)arg2)->getValue()->data()); if (arg3 != NULL && arg3->type == RVARIABLE) arg3 = get_variable(((RVariable*)arg3)->getValue()->data()); set_tmp = (arg1 != NULL && arg1->type == RNIL); if (set_tmp && operacion_es_booleana(ri->op)) arg1 = new RBool(); switch (ri->op) { case FIN : break; case PUTS : puts(arg1->to_s());break; case PUTS_COMMAND : system(((RString*)arg1)->getValue()->data());break; case GETS : gets((RString *)ri->arg1); break; case ADD : if (arg2->is_numeric() && arg3->is_numeric()){ if (!set_tmp && arg1->is_int() || arg2->is_int() && arg3->is_int()){ if (set_tmp) arg1 = new RInteger(); ((RInteger*)arg1)->setValue(((RInteger*)arg2)->getValue() + ((RInteger*)arg3)->getValue()); }else{ if (set_tmp) arg1 = new RDecimal(); ((RDecimal*)arg1)->setValue(((RNumeric*)arg2)->getDecimalValue() + ((RNumeric*)arg3)->getDecimalValue()); } }else{ if (arg2->is_string() && arg3->is_string()){ if (set_tmp) arg1 = new RString(""); ((RString*)arg1)->setValue(*((RString*)arg2)->getValue() + *((RString*)arg3)->getValue()); }else{ cout << "Error de tipos en linea " << ri->linea << " , no se puede sumar " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl; fin_error = true; } } break; case MULT : if (arg2->is_numeric() && arg3->is_numeric()){ if (!set_tmp && arg1->is_int() || arg2->is_int() && arg3->is_int()){ if (set_tmp) arg1 = new RInteger(); ((RInteger*)arg1)->setValue(((RInteger*)arg2)->getValue() * ((RInteger*)arg3)->getValue()); }else{ if (set_tmp) arg1 = new RDecimal(); ((RDecimal*)arg1)->setValue(((RNumeric*)arg2)->getDecimalValue() * ((RNumeric*)arg3)->getDecimalValue()); } }else{ if (arg2->is_string() && arg3->is_int()) { if (set_tmp) arg1 = new RString(""); string* multiplicado = new string(""); string* sumando = ((RString*)arg2)->getValue(); for (int i=0; i<((RInteger*)arg3)->getValue(); i++) *multiplicado += *sumando; ((RString*)arg1)->setValue(multiplicado); }else{ cout << "Error de tipos en linea " << ri->linea << " , no se puede multiplicar " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl; fin_error = true; } } break; case SUB : if (arg2->is_numeric() && arg3->is_numeric()){ if (!set_tmp && arg1->is_int() || arg2->is_int() && arg3->is_int()){ if (set_tmp) arg1 = new RInteger(); ((RInteger*)arg1)->setValue(((RInteger*)arg2)->getValue() - ((RInteger*)arg3)->getValue()); }else{ if (set_tmp) arg1 = new RDecimal(); ((RDecimal*)arg1)->setValue(((RNumeric*)arg2)->getDecimalValue() - ((RNumeric*)arg3)->getDecimalValue()); } }else{ cout << "Error de tipos en linea " << ri->linea << " , no se puede restar " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl; fin_error = true; } break; case DIV : if (arg2->is_numeric() && arg3->is_numeric()){ if (!set_tmp && arg1->is_int() || arg2->is_int() && arg3->is_int()){ if (set_tmp) arg1 = new RInteger(); ((RInteger*)arg1)->setValue(((RInteger*)arg2)->getValue() / ((RInteger*)arg3)->getValue()); }else{ if (set_tmp) arg1 = new RDecimal(); ((RDecimal*)arg1)->setValue(((RNumeric*)arg2)->getDecimalValue() / ((RNumeric*)arg3)->getDecimalValue()); } }else{ cout << "Error de tipos en linea " << ri->linea << " , no se puede dividir " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl; fin_error = true; } break; case POW : if (arg2->is_numeric() && arg3->is_numeric()){ if (!set_tmp && arg1->is_int() || arg2->is_int() && arg3->is_int()){ if (set_tmp) arg1 = new RInteger(); ((RInteger*)arg1)->setValue(pow(((RInteger*)arg2)->getValue(), ((RInteger*)arg3)->getValue())); }else{ if (set_tmp) arg1 = new RDecimal(); ((RDecimal*)arg1)->setValue(pow(((RNumeric*)arg2)->getDecimalValue(), ((RNumeric*)arg3)->getDecimalValue())); } }else{ cout << "Error de tipos en linea " << ri->linea << " , no se puede multiplicar " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl; fin_error = true; } break; case MOD : if (arg2->is_numeric() && arg3->is_numeric()){ if (!set_tmp && arg1->is_int() || arg2->is_int() && arg3->is_int()){ if (set_tmp) arg1 = new RInteger(); ((RInteger*)arg1)->setValue(((RInteger*)arg2)->getValue() % ((RInteger*)arg3)->getValue()); }else{ if (set_tmp) arg1 = new RDecimal(); ((RDecimal*)arg1)->setValue(((RNumeric*)arg2)->mod((RNumeric*)arg3)); } }else{ cout << "Error de tipos en linea " << ri->linea << " , no se puede multiplicar " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl; fin_error = true; } break; case SIZE: if (arg2->type == RARRAY){ arg1= ((RArray*)arg2)->size(); } else if (arg2->type == RSTRING) { arg1 = new RInteger(((RString*)arg2)->size()); } else if (arg2->type == RCLASS) { if (((RClass*)arg2)->respond_to(new RString("size"))){ call_stack.push(it); new_scope(); excecuting_current_class = (RClass*)arg2; function_info* funcion = excecuting_current_class->get_function_info((RString*)arg3); if (funcion->param_count == argument_stack.size()){ it = funcion->codigo->begin(); return_stack.push(ri->arg1); }else{ cout << "Error en linea " << ri->linea << ": cantidad erronea de argumentos, se esperaban " << funcion->param_count << " pero se encontraron " << argument_stack.size() << endl; fin_error = true; } } else { cout << "Error en linea " << ri->linea << ": el metodo " << *arg3->to_s()->getValue() << " no esta definido para " << *arg2->to_s()->getValue() << endl; fin_error = true; } } else { cout << "Error en linea " << ri->linea << ": no se puede ejecutar size de " << *arg2->get_class()->getValue() << endl; fin_error = true; } break; case IF : if (!((RBool*)arg1)->getValue()) it = descartar_if(it); cond_stack.push(((RBool*)arg1)->getValue()); break; case ELSIF : if (!((RBool*)arg1)->getValue()) it = descartar_if(it); else { cond_stack.pop(); cond_stack.push(((RBool*)arg1)->getValue());} break; case ELSIFCOND : if (cond_stack.top()) it = descartar_hasta_end(it); break; case ELSE : if (cond_stack.top()) it = descartar_hasta_end(it); break; case END : cond_stack.pop(); break; case WHILE : if (((RBool*)ri->arg1)->getValue()) while_stack.push(it); else it=descartar_whileend(it); break; case WHILEEND : if (((RBool*)ri->arg1)->getValue()) it = while_stack.top(); else while_stack.pop(); break; case CASE : if (!((RBool*)ri->arg1)->getValue()) it = descartar_case(it); cond_stack.push(((RBool*)ri->arg1)->getValue()); break; case CASEREC : if (!((RBool*)ri->arg1)->getValue()){ it = descartar_case(it); } else { cond_stack.pop(); cond_stack.push(((RBool*)ri->arg1)->getValue());} break; case CASERECCOND : if (cond_stack.top()) it = descartar_case_hasta_end(it); break; case AND : ((RBool*)arg1)->setValue(((RBool*)arg2)->getValue() && ((RBool*)arg3)->getValue()); break; case OR : ((RBool*)arg1)->setValue(((RBool*)arg2)->getValue() || ((RBool*)arg3)->getValue()); break; case NOT : ((RBool*)arg1)->setValue(!((RBool*)arg2)->getValue()); break; case G : ((RBool*)arg1)->setValue(mayor(arg2, arg3)->getValue()); break; case GE : ((RBool*)arg1)->setValue(mayor_igual(arg2, arg3)->getValue()); break; case L : ((RBool*)arg1)->setValue(menor(arg2, arg3)->getValue()); break; case LE : ((RBool*)arg1)->setValue(menor_igual(arg2, arg3)->getValue()); break; case EQ : ((RBool*)arg1)->setValue(igual(arg2, arg3)->getValue()); break; case NEQ : ((RBool*)arg1)->setValue(!igual(arg2, arg3)->getValue()); break; case TOBOOL : ((RBool*)arg1)->setValue(extraer_bool(arg2)); break; case GETV : // Evaluar variable o metodo? //ri->arg1 = get_variable((RString*)arg2); break; case GETV_ARR : // Evaluar variable o metodo? if (arg3->is_int()){ arg1 = (*((RArray *)arg2))[((RInteger *)arg3)->getValue()]; if (ri->arg1->type == RVARIABLE) set_variable((RVariable*)ri->arg1, arg1); } else{ cout << "Error de tipos en linea " << ri->linea << " , no se puede sumar " << *arg2->get_class()->getValue() << " con " << *arg3->get_class()->getValue() << endl; fin_error = true; } break; case PUT_INST_V : if (excecuting_current_class != NULL) excecuting_current_class->set_instance_variable((RString*)arg1, arg2); else set_global_variable(((RString*)arg1)->getValue(), arg2); break; case GET_INST_V : if (excecuting_current_class != NULL) arg1 = excecuting_current_class->get_instance_variable((RString*)arg2); else arg1 = get_variable(((RString*)arg2)->getValue()->data()); break; case PUTV : set_variable((RVariable*)ri->arg1, arg2); break; case PUSH_ARG: argument_stack.push(arg1); break; case POP_ARG: set_variable((RString*)arg1, argument_stack.top()); argument_stack.pop(); break; case DROP_SCOPE: drop_scope(); break; case NEW_SCOPE: new_scope(); break; case CALL: if (global_methods.find(*((RString*)arg2)->getValue()) != global_methods.end()){ call_stack.push(it); new_scope(); function_info* funcion = global_methods[(*((RString*)arg2)->getValue())]; if (funcion->param_count == argument_stack.size()){ it = get_function_iterator((RString*)arg2); return_stack.push(ri->arg1); }else{ cout << "Error en linea " << ri->linea << ": cantidad erronea de argumentos, se esperaban " << funcion->param_count << " pero se encontraron " << argument_stack.size() << endl; fin_error = true; } } else { cout << "Error en linea " << ri->linea << ": el metodo " << *arg2->to_s()->getValue() << " no esta definido!" << endl; fin_error = true; } break; case CLASS_INST_CALL: { if (((RClass*)arg2)->respond_to((RString*)arg3)){ call_stack.push(it); new_scope(); excecuting_current_class = (RClass*)arg2; function_info* funcion = excecuting_current_class->get_function_info((RString*)arg3); if (funcion->param_count == argument_stack.size()){ it = funcion->codigo->begin(); return_stack.push(ri->arg1); }else{ cout << "Error en linea " << ri->linea << ": cantidad erronea de argumentos, se esperaban " << funcion->param_count << " pero se encontraron " << argument_stack.size() << endl; fin_error = true; } } else { cout << "Error en linea " << ri->linea << ": el metodo " << *arg3->to_s()->getValue() << " no esta definido para " << *arg2->to_s()->getValue() << endl; fin_error = true; } break; } case NEW: { RClass* clase = clases[*((RString*)arg2)->getValue()]; if (clase != NULL){ arg1 = clases[*((RString*)arg2)->getValue()]->get_instance(); }else{ cout << "Error en linea " << ri->linea << ": Clase no definida" << endl; fin_error=true; } break; } case ENDFUNC: it=call_stack.top(); call_stack.pop(); drop_scope(); return_stack.pop(); break; case RETURN:{ it=call_stack.top(); call_stack.pop(); RVariable* variable = (RVariable*)return_stack.top(); return_stack.pop(); set_global_variable(variable->getValue(), arg1); drop_scope(); excecuting_current_class = NULL; break;} case WRITE_ATTR: ((RClass*)arg1)->set_instance_variable((RString*)arg2, arg3); break; case ASGN: set_variable((RString*)arg1, arg2); break; case SET_ARR_POS: { (*((RArray*)arg1)).setValue(((RInteger*)arg3)->getValue(), arg2); } break; case TO_S: ((RString*)arg1)->setValue(arg2->to_s()); break; case RESPOND_TO: ((RBool*)arg1)->setValue(arg2->respond_to(arg3->to_s())); break; case OBJECT_ID: ((RInteger*)arg1)->setValue(arg2->objectId()->getValue()); break; case INSTANCE_OF: ((RBool*)arg1)->setValue(*arg2->get_class()->getValue() == *((RString*)arg3)->getValue()); break; default: break; } if (set_tmp) set_global_variable(((RVariable*)ri->arg1)->getValue(), arg1); } while (!fin_error && ri->op != FIN); clean_up(); for (it=codigo->begin(); it != codigo->end(); it++) delete *it; if (fin_error) exit(1); }
void gol() { while (!stk.empty()) stk.pop(); }
void color(int x, int y, int c){ sx.push(x); sy.push(y); sc.push(c); si.push(0); while(!sx.empty()){ int x = sx.top(); int y = sy.top(); int c = sc.top(); int i = si.top(); sx.pop(), sy.pop(), sc.pop(), si.pop(); if(i == 0){ if(c) bcc[x][y].push_back(c); bvis[x][y] = 1; } while(i < 4){ if(ok2(x + dx[i], y + dy[i]) && !bvis[x + dx[i]][y + dy[i]]){ if(low[x + dx[i]][y + dy[i]] >= dfn[x][y]){ bcc[x][y].push_back(++col); sx.push(x); sy.push(y); sc.push(c); si.push(i+1); sx.push(x + dx[i]); sy.push(y + dy[i]); sc.push(col); si.push(0); goto T; } else{ sx.push(x); sy.push(y); sc.push(c); si.push(i+1); sx.push(x + dx[i]); sy.push(y + dy[i]); sc.push(c); si.push(0); goto T; } } i++; } T:; } }
void MWinDeviceImpl::Restore() { assert(not mState.empty()); mRenderTarget->RestoreDrawingState(mState.top()); mState.pop(); }
/**************************************************************/ #include "bbi.h" #include "bbi_prot.h" CodeSet code; /* 코드 세트 */ int startPc; /* 실행 시작행 */ int Pc = -1; /* 프로그램 카운터 -1: 실행중 아님*/ int baseReg; /* 베이스 레지스터 */ int spReg; /* 스택 포인터 */ int maxLine; /* 프로그램 끝행 */ vector<char*> intercode; /* 변환이 끝난 내부 코드 저장 */ char *code_ptr; /* 내부 코드 분석용 포인터 */ double returnValue; /* 함수 반환 값 */ bool break_Flg, return_Flg, exit_Flg; /* 제어용 플래그 */ Mymemory Dmem; /* 메모리 */ vector<string> strLITERAL; /* 문자열 리터럴 저장 */ vector<double> nbrLITERAL; /* 수치 리터럴 저장 */ bool syntaxChk_mode = false; /* 구문 검사일 때 참 */ extern vector<SymTbl> Gtable; /* 글로벌 심볼 테이블 */ class Mystack { /* stack<double> 의 랩퍼 */ private: stack<double> st; public: void push(double n) { st.push(n); } /* 넣기 */ int size() { return (int)st.size(); } /* 크기 */
/**************************************************************/ #include "bbi.h" #include "bbi_prot.h" CodeSet code; /* 코드 세트 */ int startPc; /* 실행 시작행 */ int Pc = -1; /* 프로그램 카운터 -1: 실행중 아님*/ int baseReg; /* 베이스 레지스터 */ int spReg; /* 스택 포인터 */ int maxLine; /* 프로그램 끝행 */ vector<char*> intercode; /* 변환이 끝난 내부 코드 저장 */ char *code_ptr; /* 내부 코드 분석용 포인터 */ double returnValue; /* 함수 반환 값 */ bool break_Flg, return_Flg, exit_Flg; /* 제어용 플래그 */ Mymemory Dmem; /* 메모리 */ vector<string> strLITERAL; /* 문자열 리터럴 저장 */ vector<double> nbrLITERAL; /* 수치 리터럴 저장 */ bool syntaxChk_mode = false; /* 구문 검사일 때 참 */ extern vector<SymTbl> Gtable; /* 글로벌 심볼 테이블 */ class Mystack { /* stack<double> 의 랩퍼 */ private: stack<double> st; public: void push(double n) { st.push(n); } /* 넣기 */ int size() { return (int)st.size(); } /* 크기 */ bool empty() { return st.empty(); } /* 비었는지 판정 */
void enqueue(int x){ stack1.push(x); }
void push(double n) { st.push(n); } /* 넣기 */
void Right_Extension(string &SeedStr) { int i,j; int index; int difpos;//得分相差很小的两条contig之间第一个不同的点 int MinCandidateLength;//candidate序列中的最短长度 int TotalReads;//总共的reads int MatchReads;//match上的reads int NumOfNotInf;//在所有candidate有匹配的数目 int dir;//表示方向,1表示向右,-1表示向左 string MaxScoreString;//获得最大得分的字符串 string SubSeedStr; string TempSubSeedStr; bool IsExtension; bool IsQuit; bool IsFitCondition; double perc; set<int> used; int circleLen(0); bool circled(false); while(1) { Node nd; Node tempnd;//保存从栈顶出来的元素 while(!st.empty()) st.pop();//清空栈中元素 SubSeedStr=SeedStr.substr(SeedStr.size()-lib[1].MinOverLap);//取出长度为k-mer的字串去查找index index=StrtoInt[SubSeedStr]; nd.CurStr=SubSeedStr; nd.index=index; st.push(nd); IsExtension=false; IsQuit=false; tempvec.clear(); while(!st.empty()||tempvec.size()>0)//栈不为空或者临时容器的size大于1继续 { if(st.empty()&&tempvec.size()>0)//栈中为空并且不止一个可能节点 { MinCandidateLength=tempvec[0].CurStr.size(); for(i=1;i<tempvec.size();i++)//找出candidate序列中的最短长度 { if(tempvec[i].CurStr.size()<MinCandidateLength) MinCandidateLength=tempvec[i].CurStr.size(); } IsFitCondition=false; for(i=1;i<=FileNum;i++) { for(j=0;j<tempvec.size();j++) { if(SeedStr.size()<(lib[i].MinSpan+lib[i].MaxSpan)/2) continue; if(tempvec[j].score==NegativeMin) continue; TotalReads=0; MatchReads=0; double gs=GetScore(tempvec[j].SupportStr,SeedStr,tempvec[j].CurStr.substr(0,GetMin(MinCandidateLength,lib[1].MinSpan)),i,TotalReads,MatchReads,1); if(TotalReads==0) { tempvec[j].score=NegativeMin; } else { if(MatchReads) { perc=MatchReads*1.0/TotalReads; tempvec[j].score+=gs*perc; } else { if(TotalReads==1) tempvec[j].score=0; else tempvec[j].score=NegativeMin; } } } if(tempvec.size()>0) { sort(tempvec.begin(),tempvec.end(),cmp2); NumOfNotInf=0; if(IsAllNegativeAndNoFit(tempvec,NumOfNotInf)) { IsQuit=true; break; } int veclen=tempvec.size(); if(NumOfNotInf==1) { for(j=veclen-1;j>=0;j--) { if(tempvec[j].score==NegativeMin) tempvec.pop_back(); else break; } } else { for(j=veclen-1;j>=0;j--) { if(tempvec[j].score<0) tempvec.pop_back(); else break; } } if(IsAllInCondition(tempvec,i)==true) { IsFitCondition=true; break; } } } if(IsQuit==true) break; if(IsFitCondition==false) { difpos=GetFirstDifPos(SeedStr.size(),tempvec,MinCandidateLength,1); if(difpos<lib[1].MinOverLap*1.2) IsQuit=true; else { SubSeedStr=tempvec[0].CurStr.substr(0,difpos); } break; } else { SubSeedStr=tempvec[0].CurStr; break; } } tempnd=st.top(); st.pop(); if(tempnd.CurStr.size()>MinExtensionLength) { tempnd.score=0; tempvec.push_back(tempnd);//把打到指定长度的序列存入临时容器 SubSeedStr=tempnd.CurStr; IsExtension=true; continue; } for(i=0;i<vout[tempnd.index].size();i++) { nd = tempnd; nd.index=vout[tempnd.index][i]; nd.collection.insert(nd.index); if(isused[nd.index]==true) continue; TempSubSeedStr=InttoStr[nd.index]; if(IsNodeOk(TempSubSeedStr)==false) { continue; } nd.CurStr=tempnd.CurStr.substr(0,tempnd.CurStr.size()-lib[1].MinOverLap+1)+TempSubSeedStr; st.push(nd); } } if(false==IsExtension||true==IsQuit) break; else { SeedStr=SeedStr.substr(0,SeedStr.size()-lib[1].MinOverLap)+SubSeedStr; for(set<int>::iterator it=tempvec[0].collection.begin();it!=tempvec[0].collection.end();it++) { if(used.find(*it)!=used.end()){ if(circled){ circleLen += (InttoStr[*it].length() - lib[1].MinOverLap + 1); }else{ circled = true; circleLen += (InttoStr[*it].length() - lib[1].MinOverLap + 1); } if(circleLen>lib[FileNum].MaxSpan){ ofile<<"right"<<endl; if(circleLen>SeedStr.length())ofile<<circleLen<<' '<<SeedStr.length()<<endl; else SeedStr = SeedStr.substr(0,SeedStr.length() - circleLen); return;; } }else{ used.insert(*it); circled = false; circleLen = 0; } } } } }
void push(int x){ int minim=s1.empty()?x:min(x,s1.top().second); s1.push(make_pair(x,minim)); }
bool empty(void){ return s1.empty() && s2.empty(); }
void transfere() { while (!s_2.empty()) { s_1.push(s_2.top()); s_2.pop(); } }
/**************************************************************/ #include "bbi.h" #include "bbi_prot.h" CodeSet code; /* 코드 세트 */ int startPc; /* 실행 시작행 */ int Pc = -1; /* 프로그램 카운터 -1: 실행중 아님*/ int baseReg; /* 베이스 레지스터 */ int spReg; /* 스택 포인터 */ int maxLine; /* 프로그램 끝행 */ vector<char*> intercode; /* 변환이 끝난 내부 코드 저장 */ char *code_ptr; /* 내부 코드 분석용 포인터 */ double returnValue; /* 함수 반환 값 */ bool break_Flg, return_Flg, exit_Flg; /* 제어용 플래그 */ Mymemory Dmem; /* 메모리 */ vector<string> strLITERAL; /* 문자열 리터럴 저장 */ vector<double> nbrLITERAL; /* 수치 리터럴 저장 */ bool syntaxChk_mode = false; /* 구문 검사일 때 참 */ extern vector<SymTbl> Gtable; /* 글로벌 심볼 테이블 */ class Mystack { /* stack<double> 의 랩퍼 */ private: stack<double> st; public: void push(double n) { st.push(n); } /* 넣기 */ int size() { return (int)st.size(); } /* 크기 */ bool empty() { return st.empty(); } /* 비었는지 판정 */ double pop() { /* 읽기 & 삭제(원래 pop와 다르니 주의 */ if (st.empty()) err_exit("stack underflow"); double d = st.top(); /* 스택 탑의 값 */ st.pop(); return d; /* 하나 삭제 */ }
void push(int data) { s_2.push(data); }
void GetDit(int num){ while(num){ s.push(num % 10); num /= 10; } }
int front() { if (s_1.empty()) { transfere(); } return s_1.top(); }
void find_scc() { dfs_clock=scc_cnt=0; CLR(low);CLR(pre);CLR(in); while (S.size()) S.pop(); for (int i=1;i<=n;i++) if (!pre[i]) dfs(i); }
/** @return whether we have a next smallest number */ bool hasNext() { if(s.empty()) return false; return true; }
void clear(){ while(!(head->empty()))head->pop(); while(!(rear->empty()))rear->pop(); }
void dfs(int x, int y, int px, int py){ tx.push(x); ty.push(y); ptx.push(px); pty.push(py); ti.push(0); while(!tx.empty()){ int x = tx.top(); int y = ty.top(); int px = ptx.top(); int py = pty.top(); int i = ti.top(); tx.pop(), ty.pop(), ptx.pop(), pty.pop(), ti.pop(); if(i == 0){ dfn[x][y] = low[x][y] = ++piv; par[x][y] = pi(px, py); size[x][y] = 1; } while(i < 4){ if(x + dx[i] == px && y + dy[i] == py){ i++; continue; } if(ok2(x + dx[i], y + dy[i])){ if(!dfn[x + dx[i]][y + dy[i]]){ tx.push(x); ty.push(y); ptx.push(px); pty.push(py); ti.push(i+1); tx.push(x + dx[i]); ty.push(y + dy[i]); ptx.push(x); pty.push(y); ti.push(0); goto T; } else{ low[x][y] = min(low[x][y], dfn[x + dx[i]][y + dy[i]]); } } i++; } if(i == 4){ low[px][py] = min(low[px][py], low[x][y]); size[px][py] += size[x][y]; } T:; } }
int main() { int n; cin >> n; for(int i=0;i<n;i++) { cin >> str[i]; if(str[i]=="PUSH"||str[i]=="IFZERO") cin >> op[i]; } int reg; int instruct=0; while(str[instruct]!="DONE") { if(str[instruct]=="PUSH") { sta.push(op[instruct]); instruct++; } if(str[instruct]=="STORE") { int temp = sta.top(); sta.pop(); reg = temp; instruct++; } if(str[instruct]=="LOAD") { sta.push(reg); instruct++; } if(str[instruct]=="PLUS") { int a=sta.top(); sta.pop(); int b= sta.top(); sta.pop(); sta.push(a+b); instruct++; } if(str[instruct]=="TIMES") { int a=sta.top(); sta.pop(); int b= sta.top(); sta.pop(); sta.push(a*b); instruct++; } if(str[instruct]=="IFZERO") { int temp = sta.top(); sta.pop(); if(temp==0) instruct=op[instruct]; else instruct++; } } cout <<sta.top() <<endl; }
int main() { ios_base :: sync_with_stdio(false); cin >> N; for (int i = 1; i <= N; ++ i) cin >> v[i]; v[0] = v[N + 1] = NMAX; stk.push(0); for (int i = 1; i <= N; ++ i) { while (!stk.empty() && v[stk.top()] < v[i]) stk.pop(); st1[i] = stk.top() + 1; stk.push(i); } gol(); stk.push(N + 1); for (int i = N; i; -- i) { while (!stk.empty() && v[stk.top()] <= v[i]) stk.pop(); dr1[i] = stk.top() - 1; stk.push(i); } gol(); v[0] = v[N + 1] = 0; stk.push(0); for (int i = 1; i <= N; ++ i) { while (!stk.empty() && v[stk.top()] > v[i]) stk.pop(); st2[i] = stk.top() + 1; stk.push(i); } gol(); stk.push(N + 1); for (int i = N; i; -- i) { while (!stk.empty() && v[stk.top()] >= v[i]) stk.pop(); dr2[i] = stk.top() - 1; stk.push(i); } lint sum1 = 0; lint sum2 = 0; for (int i = 1; i <= N; ++ i) { sum1 += (i - st1[i] + 1LL) * (dr1[i] - i + 1LL) * v[i]; sum2 += (i - st2[i] + 1LL) * (dr2[i] - i + 1LL) * v[i]; } cout << sum1 - sum2 << '\n'; return 0; }
void llena_pila(stack<int> &pila, int tam) { for (int i = 0; i < tam; ++i) { pila.push(i); } }
int main(int argc, const char * argv[]) { int n, l; cin >> n >> l; int i; int pos = -1; lb = point(99999, 99999); for (i = 0; i < n; i++) { cin >> points[i].x >> points[i].y; if (points[i].y <= lb.y) { if (points[i].y < lb.y || points[i].x < lb.x) { lb = points[i]; pos = i; } } } point tt = points[0]; points[0] = lb; points[pos] = tt; qsort(points, n, sizeof(point), cmp); st.push(lb); st.push(points[0]); st.push(points[1]); int cur = 2; while (cur < n - 1) { point c = points[cur++]; point top = st.top(); point sec = getSecond(); while (!leftTurn(sec, top, c)) { st.pop(); if (st.size() == 1) break; top = st.top(); sec = getSecond(); } st.push(c); } double length = 0.0; length += 2 * PI * l; point start = st.top(); point cc = st.top(); st.pop(); while (!st.empty()) { point tmp = st.top(); length += dis(cc, tmp); cc = tmp; st.pop(); } length += dis(start, cc); cout << (int)(length + 0.5) << endl; return 0; }
/*********************************************************************** * * * Name: maker Date: 28.09.00 * * Author: Evgeni Chernyaev Revised: * * * * Function: Executes basic arithmetic operations on values in the top * * of the stack. Result is placed back into the stack. * * This function is used by engine(). * * * * Parameters: * * op - code of the operation. * * val - stack of values. * * * ***********************************************************************/ static int maker(int op, stack<double> & val) { if (val.size() < 2) return EVAL::ERROR_SYNTAX_ERROR; double val2 = val.top(); val.pop(); double val1 = val.top(); switch (op) { case OR: // operator || val.top() = (val1 || val2) ? 1. : 0.; return EVAL::OK; case AND: // operator && val.top() = (val1 && val2) ? 1. : 0.; return EVAL::OK; case EQ: // operator == val.top() = (val1 == val2) ? 1. : 0.; return EVAL::OK; case NE: // operator != val.top() = (val1 != val2) ? 1. : 0.; return EVAL::OK; case GE: // operator >= val.top() = (val1 >= val2) ? 1. : 0.; return EVAL::OK; case GT: // operator > val.top() = (val1 > val2) ? 1. : 0.; return EVAL::OK; case LE: // operator <= val.top() = (val1 <= val2) ? 1. : 0.; return EVAL::OK; case LT: // operator < val.top() = (val1 < val2) ? 1. : 0.; return EVAL::OK; case PLUS: // operator '+' val.top() = val1 + val2; return EVAL::OK; case MINUS: // operator '-' val.top() = val1 - val2; return EVAL::OK; case MULT: // operator '*' val.top() = val1 * val2; return EVAL::OK; case DIV: // operator '/' if (val2 == 0.0) return EVAL::ERROR_CALCULATION_ERROR; val.top() = val1 / val2; return EVAL::OK; case POW: // operator '^' (or '**') errno = 0; val.top() = pow(val1,val2); if (errno == 0) return EVAL::OK; default: return EVAL::ERROR_CALCULATION_ERROR; } }
void reset(){ while(!s.empty()) s.pop(); while(!q.empty()) q.pop(); while(!pq.empty()) pq.pop(); isStack=1, isQueue=1, isPQueue=1; }
int main() { int i, j, k; int m, n, tc; int prev, next; int len; string ss; //freopen("f:\\in.txt", "r", stdin); //freopen("f:\\out.txt", "w", stdout); scanf("%d", &tc); while (tc--) { scanf("%s", buff); f.clear(); k = 0; len = strlen(buff); prev = get_state(buff[0]); for (i=0; buff[i]; ++i) { next = get_state(buff[i]); if (next == prev && prev == DIGIT) { word[k++] = buff[i]; } else { if (k > 0) { word[k] = '\0'; f.push_back(string(word)); k = 0; } word[0] = buff[i], word[1] = '\0'; f.push_back(string(word)); } prev = next; } if (k > 0) { word[k] = '\0'; f.push_back(string(word)); } //for (i=0; i!=f.size(); ++i) puts(f[i].c_str()); puts(""); while (!s.empty()) s.pop(); for (i=0; i!=f.size(); ++i) { if (s.empty()) { s.push(f[i]); } else { if (f[i] == "(") { s.push(f[i]); } else if (f[i] == ")") { string t(""); while (!temp.empty()) temp.pop(); while (true) { ss = s.top(); s.pop(); if (ss == "(") break; temp.push(ss); } while (!temp.empty()) { t += temp.top(); temp.pop(); } if (!s.empty()) { ss = s.top(); if (is_digit(ss)) { s.pop(); string tt(""); len = to_digit(ss); for (k=0; k<len; ++k) tt += t; s.push(tt); } } } else if (is_digit(f[i])) { s.push(f[i]); } else { ss = s.top(); if (is_digit(ss)) { s.pop(); string tt(""); len = to_digit(ss); for (k=0; k<len; ++k) tt += f[i]; s.push(tt); } else { s.push(f[i]); } } } } ss.clear(); while (!temp.empty()) temp.pop(); while (!s.empty()) { temp.push(s.top()); s.pop(); } while (!temp.empty()) { ss += temp.top(); temp.pop(); } puts(ss.c_str()); } return 0; }