Example #1
0
 virtual shared_ptr<MenuComponent> move(MenuLeaf& m, KeyButton& k) {
   switch (k.get_key()) {
     case BUTTON_UP:
       return (history.top().get().get_previous_element());
     case BUTTON_DOWN:
       return (history.top().get().get_next_element());
     case BUTTON_LEFT:
       if (history.size() > 1) {
         history.top().get().home();
         history.pop();
       }
       return (history.top().get().get_active_element());
     case BUTTON_RIGHT:
       return (history.top().get().get_active_element());
     default:
       throw MenuException((string("Unexpected key ") + string(k)).c_str());
       break;
   }
 }
Example #2
0
            bool shift_reduce( const T& c ) {
                while ( stack_.top().distance() < width_ ) {
                    // && stack_.top().type() == peakfind::Down ) { // discard narrow 'down' state
                    stack_.pop();
                    if ( stack_.empty() ) {
                        stack_.push( c );
                        return false;
                    }
                }

                if ( stack_.top().type() == c.type() )  // marge
                    stack_.top() += c;  // marge

                // if (Up - Down)|(Down - Up), should push counter and wait for next state
                if ( stack_.top().type() != c.type() )
                    stack_.push( c );

                return stack_.size() >= 3;
            };
Example #3
0
int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++)
        scanf("%d %d", lf+i, rg+i);
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (lf[i] > lf[j] && rg[i] < rg[j])
                adj[j].push_back(i);
        }
    }

    int maxi = 0;
    for (int i = 0; i < n; i++)
        hei[i] = -1;

    for (int i = 0; i < n; i++) {
        dfs(i);
        if (hei[maxi] < hei[i])
            maxi = i;
    }
    
    printf("%d\n", hei[maxi]);

    while (hei[maxi] != 1) {
        st.push(maxi+1);
        for (int i = 0; i < adj[maxi].size(); i++) {
            if (hei[adj[maxi][i]] == hei[maxi] - 1) {
                maxi = adj[maxi][i];
                break;
            }
        }
    }
    st.push(maxi+1);

    while (st.size() > 1) {
        printf("%d ", st.top());
        st.pop();
    }

    printf("%d\n", st.top());
}
GFXBOOL /*GFXDRVAPI*/ GFXPopGlobalEffects()
{
    if ( GlobalEffects.empty() )
        return false;
    //VSFileSystem::Fprintf (stderr,"GES %d",GlobalEffects.size());
    for (int i = 0; i < GFX_MAX_LIGHTS; i++)
        if (GlobalEffects.top()[i])
            glEnable( GL_LIGHT0+i );
    
    if (GlobalEffectsFreelist.size() >= 10)
        delete[] GlobalEffects.top();
    else
        GlobalEffectsFreelist.push(GlobalEffects.top());
    GlobalEffects.pop();
    
    GFXLightContextAmbient( GlobalEffectsAmbient.top() );
    GlobalEffectsAmbient.pop();
    return true;
}
Example #5
0
int main()
{
    int i,n;
    char s;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>s;
        if(st.empty()){
            st.push(s);
            continue;
        }
        char r=st.top();
        if(r!=s){
            st.pop();
        }else{
            st.push(s);
        }
    }
    cout<<st.size();
}
 void op(string& opCode)
 {
   if(s.size() >= 2) {
     double a = s.top(); s.pop();
     double b = s.top(); s.pop();
     double result;
          if(opCode == "+") result = b + a;
     else if(opCode == "-") result = b - a;
     else if(opCode == "*") result = b * a;
     else if(opCode == "/") result = b / a;
     else if(opCode == "%") result = fmod(b, a);
     else {
       cout << "unknown operator " << opCode << "\n";
       return;
     }
     cout << result << "\n";
     s.push(result);
   } else
     cout << "need two numbers\n";
 }
/* ------------------------------- To handle self closing tags on stack ----------------------------------*/
void XMLParser::handleSelfCloseTags(XmlReader newxrdPtr, stack<shared_ptr <AbstractXmlElement>> &impStack, string element, string temp, size_t s)
{
	using sPtr = shared_ptr < AbstractXmlElement >;
	if (impStack.size() != 0){
		sPtr pop0 = impStack.top();
		impStack.pop();
		newxrdPtr.position(s + 1);

		sPtr child = makeTaggedElement(newxrdPtr.tag());
		if (containsTagsText(newxrdPtr, child)){}
		containsAttribute(newxrdPtr, child);
		child->selfCloseTag(1);

		if (pop0->numofChild() > 0)	{
			pop0->addChild(child);
			pop0->getNumofChilds(pop0->numofChild() - 1);
			impStack.push(pop0);
		}
	}
}
Example #8
0
// Display the stack in "pop" order
template<> void debug::dump<stack<int>>(const string& msg,  const stack<int>& indecies)  noexcept
{
    cout << msg;
    
    struct Hack : public stack<int> {

        static int item(int i, const stack<int>& stack_ref)
        {
            return (stack_ref.*&Hack::c)[i];
        }
    };
    
    for(int i = indecies.size() - 1; i >= 0;  --i) {
      //    for(int i = 0;  i < indecies.size();  ++i) {

        cout << Hack::item(i, indecies) << ", ";
    }

    cout << endl;
}
char* infixToPostfix(char *s){
	int i=0;	//loop variable
	int prior,n;
	char *postfix;
	while(s[i]!='\0'){
		prior=priority(s[i]);
		if(prior<0)
			expres.push(s[i]);
		else insert(s[i],prior);
		i++;
	}
	while(!aux.empty()){
		expres.push(aux.top());
		aux.pop();
	}
	n=expres.size();
	postfix=new char[n+1];
	FOR(i,n){
		postfix[n-i-1]=expres.top();
		expres.pop();
	}
Example #10
0
//This is also a helper function for UNDO command, return the previous turn result
void Board::undo() {
	if (undo_counter < 10) {
		if (undo_list.size() != 0) {      //undo_list contains some previous turns
			gameboard = undo_list.top();
			undo_list.pop();
			if (previous_turn() == 1) {
				undo();
			}
			else {              //undo_list is empty
				turn = -1;
				undo_counter++;
				show();
				cout << 10 - undo_counter << " UNDO remain\n";
			}
		}
		else
			cout << "no more undo steps" << endl;
	}
	else
		cout << "at most undo 10 times\n";
}
void specialStack::push(int data){
	s.push(data);
	if(sm.empty()){
		Min *tmp = new Min;
		tmp->data = data;
		tmp->ind = 0;
		sm.push(tmp);
	}
	else {
		Min *t = sm.top();
		if(t->data < data){
			sm.top()->ind++;
		}
		else {
			Min *tmp = new Min;
			tmp->data = data;
			tmp->ind = s.size()-1;
			sm.push(tmp);
		}
	}
}
inline llint fact( llint n ) {
    llint ret = 1;
    int l1,l2;
    l1 = prost.size();
    for( int x = 0; x < l1 && n != 1; x++ ) {
        uzet.push( x );
        while( n % prost[x] == 0 )
            n /= prost[x], niz[x] *= prost[ x ];
        if( niz[ x ] == 1 )
            uzet.pop();
    }
    if( n != 1 ) {
        ret *= calc( n, n );
    }
    while( uzet.size() ) {
        ret *= calc( niz[ uzet.top() ], prost[ uzet.top() ] );
        niz[ uzet.top() ] = 1;
        uzet.pop();
    }
    return ret;
}
/* ------------------------------- To handle Process Instructions ----------------------------------*/
void XMLParser::handleProcInstr(XmlReader newxrdPtr, stack<shared_ptr <AbstractXmlElement>> &impStack, string element, string temp, size_t s)
{
	using sPtr = shared_ptr < AbstractXmlElement >;
	if (impStack.size() != 0)	{
		sPtr pop0 = impStack.top();
		impStack.pop();

		newxrdPtr.position(s + 1);
		sPtr child = makeProcInstrElement(newxrdPtr.tag());
		s = newxrdPtr.tag().size() + 1;
		vector<string> attrvalue = getManualAttre(getString(s, temp.size() -1 , temp));
		for (size_t i = 0; i < attrvalue.size(); i += 2)
		{	child->addAttrib(attrvalue[i], attrvalue[i + 1]);	}
		child->selfCloseTag(1);
		if (pop0->numofChild() > 0){
			pop0->addChild(child);
			pop0->getNumofChilds(pop0->numofChild() - 1);
			impStack.push(pop0);
		}
	}
}
Example #14
0
void sort_root(vector<int> &v)
{
	vector<vstore> values, temp;
	vector<vstore>::iterator it;
	vstore pop;
	while (sstore.size() != 0)
	{
		pop = sstore.top();
		temp.push_back(pop);
		sstore.pop();
	}
	while (temp.size() != 0)
	{
		values.push_back(temp[temp.size() - 1]);
		temp.pop_back();
	}
	size_t least = 0;
	for (int i = 0; i < values.size() - 1; i++)
	{
		least = i;
		for (int j = i + 1; j < values.size(); ++j)
		{
			if (v[values[j].second] < v[values[least].second])
			{
				cond_check = 1;
				least = j;
			}
		}
		int idx = values[least].second; 
		int temp = v[idx];
		int idx1 = values[i].second;
		int temp1 = v[idx1];
		v[values[i].second] = temp;
		v[values[least].second] = temp1;
	}
	for (int i = 0; i < values.size(); i++)
	{
		sstore.push(values[i]);
	}
}
Example #15
0
//////////////////////////////////////////////////////////////////////////
// 在dc上绘制单个点像素
void ptdDoPaintSingleDot(HDC hdc)
{
	if (flag == 0)
	{

		num = rand() % max_num;
		COLORREF color;
		pair<int, int> temp_pots;
		temp_pots.first = gaussrand(arr[num][0] * 13, 5);
		temp_pots.second = gaussrand(arr[num][1] * 13, 5);
		pots_stack.push(temp_pots);
		if (pots_stack.size() > 18000)
		{
			flag = 1;
		}
		if (arr[num][5] == 1)
		{
			color = RGB(255, gaussrand(arr[num][3] * 0.5, 60), gaussrand(arr[num][4] * 0.5, 60));
		}
		else
		{
			color = RGB(arr[num][2] * 1.2, 255, arr[num][4] * 1.2);
		}

		SetPixel(hdc, temp_pots.first, temp_pots.second, color);
	}
	else
	{
		SetPixel(
			hdc,
			pots_stack.top().first,
			pots_stack.top().second,
			RGB(0, 0, 0));
		pots_stack.pop();
		if (pots_stack.empty())
		{
			flag = 0;
		}
	}
}
Example #16
0
int main(){
	int cs = 1;
	while( scanf("%s", s) != EOF ){
		if( s[0] == '-' ) break;
		while(!sta.empty()) sta.pop();
		int ans = 0;
		for(int i=0 ; s[i] ; ++i){
			if( s[i] == '{' )
				sta.push(s[i]);
			else {
				if( sta.empty() ){
					sta.push(s[i]);
					ans++;
				}
				else sta.pop();
			}
		}
		ans += sta.size()/2;
		printf("%d. %d\n", cs++, ans);
	}
	return 0;
}
Example #17
0
File: A1051.cpp Project: ZGWJ/PAT
int main(){
    scanf("%d %d %d",&n,&m,&k);
    
    for (int i=0; i<k; i++) {
        while (!st.empty()) {
            st.pop();
        }
        
        for (int j=0; j<m; j++) {
            scanf("%d",&arr[j]);
        }
        
        int current=0;
        
        bool flag=true;
        
        for (int j=1; j<=m; j++) {
            st.push(j);
            
            if (st.size()>n) {
                flag=false;
                break;
            }
            
            while (!st.empty()&&st.top()==arr[current]) {
                st.pop();
                current++;
            }
        }
        
        if (st.empty()==true&&flag==true) {
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    
    return 0;
}
Example #18
0
void takeQueries() {
    int x,y;

    int ch;
    //printf("Please Choose one of the following :\n1.Insert Interval(0-15)\n2.Query a point\n");
    //scanf("%d",&ch);

    while(st.size()>0) {
        greens gr = st.top();
        glColor3fv(normal);
        displayNode(gr.x, gr.y, gr.v, gr.sz);
        st.pop();
    }

    if(done < num) {
        x=intervals[done].l;
        y=intervals[done].r;
        done++;
        //scanf("%d%d",&x,&y);
            glColor3fv(updateRecursing);
            wait = 1;
            getSum(x,y);
            glColor3fv(updateRecursing);
            wait = 0;
        system("pause");
    } else  {
        scanf("%d",&x);
            wait = 1;
            y=cnt(1, 0, n-1, x, stx, sty, n * sepx * 5);
            printf("result of stabbing query is : %d\n",y);
            wait = 0;
            system("pause");
    }


    //Sleep(500);
    glutPostRedisplay();
}
Example #19
0
void sort_stack(stack<T>& s)
{
    stack<T> helper;
    while (s.size() > 0) {
        T t = s.top();
        s.pop();
        if (helper.empty() || t >= helper.top()) {
            helper.push(t);
            continue;
        }
        
        while (helper.size() > 0) {
            T h = helper.top();
            if (t >= h) {
                break;
            }
            s.push(h);
            helper.pop();
        }
        helper.push(t);
    }
    s.swap(helper);
}
string combine(stack<int> s){
    string units[] = {"billion", "million", "thousand", ""};
    
    int size = 4-(int)s.size();
    
    string result  = "";
    
    while (!s.empty()){
        
        int x = s.top();
    
        if (x==0){
            size++;
        }else{
            result += threeToString(x);
            result += units[size++];
        }
        result += " ";
        s.pop();
    }
    
    return result;
}
Example #21
0
int genGetChar (char *buf)
{
	if (passNL)
	{
		buf[0] = '\n';
		passNL = false;
		return 1;
	}
	int c = fgetc (files.top ());
	if (c == EOF)
	{
		if (files.size () > 1)
		{
			fclose (files.top ());
			files.pop ();
			yylineno = lineno.top ();
			lineno.pop ();
			filenames.pop ();
			c = fgetc (files.top ());
		}
	}
  return (c == EOF) ? 0 : (buf[0] = c, 1); 
}
bool parse(string& time,string& name,string& action) 
{
    record cur;
    if(action=="START")
        cur.action=0;
    else if(action=="END")
        cur.action=1; 
    else
        return false;
    sscanf(time.c_str(),"%d:%d:%d",&(cur.hh),&(cur.mm),&(cur.ss));
    if(!cur.isValid())
        return false;
    if(pre.action!=-1) {
        record delta=cur-pre;
        if(!delta.isValid())
            return false;
    }
    pre=cur;
    if(!cur.action) {
        order.push_back(name);
        track.push(make_pair(name,cur));
        result[name]=cur;
    }
    else {
        if(track.size()==0)
            return false;
        pair<string,record> top=track.top();
        track.pop();
        if(name!=top.first)
            return false;
        record diff=cur-top.second;
        if(!diff.isValid())
            return false;
        result[name]=diff;
    }
    return true;
}
Example #23
0
File: CUtil.cpp Project: sun736/UCC
size_t CUtil::NestedIfDup(string &cc4_valid_if, stack<string> &cc4_parent_stack, stack<set<string> > &cyclomatic_distinct_cond_stack, set<string> &nested_set){


    //cc4_valid_if && cc4_parent_stack.top()
    set<string> temp_set = cyclomatic_distinct_cond_stack.top();
    set<string>::iterator it;
    string parent = cc4_parent_stack.top();
    size_t dup_counter=0;

    if(cyclomatic_distinct_cond_stack.size()==1){
        string combine = parent + "&&" + cc4_valid_if;

        if(nested_set.find(combine)!=nested_set.end()){
            cout << "already counted the dup" << endl;
            return 0;

        }
        nested_set.insert(combine);
        cout << "-----insest " << combine << " to nested_set"<<endl;
        if(temp_set.find(combine)!=temp_set.end()){
            //can find a && dup, counter && number
            return CountNestedNum(combine);
        }
        return 0;


    }

    cyclomatic_distinct_cond_stack.pop();
    cc4_parent_stack.pop();
    string new_cc4_valid_if = parent+"&&"+cc4_valid_if;
    dup_counter = NestedIfDup(new_cc4_valid_if, cc4_parent_stack, cyclomatic_distinct_cond_stack, nested_set);
    cyclomatic_distinct_cond_stack.push(temp_set);
    cc4_parent_stack.push(parent);

    return dup_counter;
}
 void binaryTreePathsImpl(stack<int>& path, TreeNode* root, vector<string>& solution)
 {
     path.push(root->val);
     if (root->left == NULL && root->right == NULL)
     {
         stack<int> currentPath;
         while (path.size() > 0)
         {
             currentPath.push(path.top());
             path.pop();
         }
         ostringstream buffer;
         while (currentPath.size() > 1)
         {
             buffer << currentPath.top();
             buffer << "->";
             path.push(currentPath.top());                    
             currentPath.pop();
         }
         buffer << currentPath.top();
         path.push(currentPath.top());
         currentPath.pop();
         solution.push_back(buffer.str());
     }
     else
     {
         if (root->left != NULL)
         {
             binaryTreePathsImpl(path, root->left, solution);
         }
         if (root->right != NULL)
         {
             binaryTreePathsImpl(path, root->right, solution);
         }
     }
     path.pop();
 }
int get(string s)
{
	int i,l;
	l=s.size();
	if(l%2!=0)
	{
		return -1;
	}
	int ans=0;
	for(i=0;i<l;i++)
	{
		if(s[i]=='{')
		{
			st.push(s[i]);
		}
		else
		{
			if(st.empty())
			{
				s[i]='{';
				st.push(s[i]);
				ans++;
			}
			else
			{
				st.pop();
			}
		}
	}
	ans+=st.size()/2;
	while(!st.empty())
	{
		st.pop();
	}
	return ans;
}
Example #26
0
int main()
{
    ifstream f("paranteze2.in");
    ofstream g("paranteze2.out");
    f>>ss;
    for(int i=0; i<ss.size(); ++i) {
        c=ss[i];
        if(c=='(') s.push(mp(c,i));
        else {
            if(s.size()){
                per tp=s.top();
                if(tp.x=='(') {
                    cx[++sz]=tp.y;
                    cy[sz]=i;
                    s.pop();
                }else s.push(mp(c,i));
            }else s.push(mp(c,i));
        }
    }
    for(int i=1; i<=sz; ++i) dp[cy[i]]=dp[cx[i]-1]+1LL;
    for(int i=0; i<DN; ++i) rez+=dp[i];
    g<<rez;
    return 0;
}
Example #27
0
  // Rozdeleni pracovniho zasobniku na stavy, ktere si necham a stavy, ktere odeslu
  // Odesilam stav ze dna zasobniku
 	string splitStack(stack<string>& workStack) {
	  // Neni dostatek dat na rozdeleni prace
	  if (workStack.size() < 2) {
  	      return "";
	  }

	  stack<string> tempStack;

	  while (!workStack.empty()) {
      tempStack.push(workStack.top());
	      workStack.pop();
	  }

	  string response = tempStack.top();
	  tempStack.pop();

	  while (!tempStack.empty()) { 
	      workStack.push(tempStack.top());
	      tempStack.pop();
	  }

	  return response;
	  //TODO kontrola jestli se posilany stav vyplati poslat
	}
int main()
{
    int n,a;
    scanf("%d",&n);
    for(int i=0;i<n*2;i++)
    {
            scanf("%d",&a);a--;
            if(czy[a]==0)
            {
                  czy[a]=1;
                  s.push(a);
            }
            else
            {
                  while(s.top()!=a)
                  {
                         ruchy.push(s.size());
                         temp.push(s.top());
                         s.pop();
                  }
                  s.pop();
                  while(!temp.empty())
                  {
                                      s.push(temp.top());
                                      temp.pop();
                  }
            }
    }
    printf("%d\n",ruchy.size());
    while(!ruchy.empty())
    {
                     printf("%d\n",ruchy.front());
                     ruchy.pop();
    }
    return 0;
}
Example #29
0
int BasicCal::calculate(string s){
    string num = "";
    for(int i = s.size() - 1; i >= 0; --i){
        char c = s[i];
        if(isdigit(c)){
            num = c + num;
            if(i == 0){
                cout << "num:" << num << endl;
                operands.push(stoi(num));
            }
        } else {
            cout << "num:o" << num << endl;
            // check empyt!!
            if(!num.empty()){
                operands.push(stoi(num));
            }
            num = "";
            switch(c){
                case '+':
                case '-':
                case ')':
                    operators.push(c);
                break;
                case '(':
                    while(operators.top() != ')'){
                        calc();
                    }
                    operators.pop();
            } 
        }
    }
    while(operands.size() != 1){
        calc();
    }
    return operands.top();
}
Example #30
0
 void g(vector<string> &v, stack<string> s, 
        int left, int right, int n) {
     if (left == n && right == n) {
         string x = "";
         while (s.size() > 0) {
             x = s.top() + x; // note: can't be x + s.top().
             s.pop();
         }
         v.push_back(x);
         return;
     }
     
     if (left > right) {
         s.push(")");
         g(v, s, left, right + 1, n);
         s.pop();
     }
     
     if (left < n) {
         s.push("(");
         g(v, s, left + 1, right, n);
         s.pop();
     }
 }