STL Sector applications

Source: Internet
Author: User

1#include <iostream>2#include <string>3#include <vector>4#include <cstdio>5 using namespacestd;6 intN;7vector<int> pile[ -];8 9 //find the pile and height of a where the caller is returned as an application,Ten voidFind_block (intAint&p,int&h) One { A      for(p=0;p <n;p++) -          for(h=0; H<pile[p].size (); h++) -             if(pile[p][h]==a) the     return ; - } -  - voidClear_above (intPinth) + { -      for(inti=h+1; I<pile[p].size (); i++) +     { A         intb=Pile[p][i]; at Pile[b].push_back (b); -     } -Pile[p].resize (H +1); - } - voidPile_onto (intPintHintp2) - { in      for(intI=h;i<pile[p].size (); i++) The capacity size of the//pile[p].size () - Pile[p2].push_back (Pile[p][i]); to pile[p].resize (h);//pile[p] capacity changed to H size + } - voidprint () the { *      for(intI=0; i<n;i++) $     {Panax Notoginsengprintf"%d:", i); -          for(intj=0; J<pile[i].size (); j + +) theprintf"%d", Pile[i][j]); +printf"\ n"); A     } the } +      -  $ intMain () $ { -     intb; -scanf"%d",&n); the     strings1,s2; -      for(intI=0; i<n;i++)    Wuyi Pile[i].push_back (i); the      while(cin>>s1>>a>>s2>>b) -     { Wu         intPA,PB,HA,HB; - Find_block (a,pa,ha); About Find_block (B,PB,HB); $         if(pa==pb) -             Continue; -         if(s2=="onto") Clear_above (PB,HB); -         if(s1=="Move") Clear_above (pa,ha); A Pile_onto (PA,HA,PB); + print (); the     } -      $     return 0; the}

Vector class:

Pile[p].size () See Capacity size

Pile[p].resize (n) resizing the vector container

Pile[p].empty () to determine if it is empty
Begin () and end () functions--Returns the position of the first element and the last element

The front () and back () functions return the first and last elements of a vector

Push_back (x) and Pop_back () finally insert an element in the vector and delete an element

Vectors can be the same as the array, using the following table to indicate

STL Sector applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.