Uva 12096.The setstack Computer

Source: Internet
Author: User
Tags switch case

Well...... The big idea of the problem is obvious, but the details are so annoying ...

It's basically stack+set.

For the elements in the stack, you can see that each element is a collection (set), and the elements in the collection are also collections

Therefore, each set (element) should be numbered typedef SET<int> element, so that each element can be treated as a stack stack s that holds integers ;

Map sets (elements) and numbering with map and vector

map<element,int> id_eache;vector<int> id_eache2;

And then you can write it on demand.

The switch case can be used to determine the operation.

Be aware that each case requires a break ;

Because case is only the entrance, not the exit . If you go in there, you'll run without a break.

1#include <cstdio>2#include <Set>3#include <stack>4#include <iostream>5#include <map>6#include <vector>7 using namespacestd;8 9 classlove{Ten     Private: One         intN; AtypedefSet<int>element; -Stack <int>s; -  theMap<element,int>Id_cache; -Vector<element>id_cache2; -  -         intID (element x) { +             if(Id_cache.count (x))returnId_cache[x]; - id_cache2.push_back (x); +             returnId_cache[x]=id_cache2.size ()-1; A         } at  -      Public: -         voidstart () { -scanf"%d",&n); -             Charcom[Ten]; -              while(n--){ inscanf"%s", com); - element Temp1,temp2,temp3; to element::iterator it1,it2,it; +                 Switch(com[0]){ -                      Case 'P': the S.push (ID (Element () )); *                          Break; $                      Case 'D':Panax Notoginseng S.push (S.top ()); -                          Break; the                      Case 'U': +temp1=id_cache2[s.top ()]; A S.pop (); theTemp2=id_cache2[s.top ()]; + S.pop (); -                          for(It=temp2.begin (); It!=temp2.end (); it++) $Temp1.insert (*it); $ S.push (ID (TEMP1)); -                          Break; -                      Case 'I': thetemp1=id_cache2[s.top ()]; - S.pop ();WuyiTemp2=id_cache2[s.top ()]; the S.pop (); -                          for(It1=temp1.begin (); It1!=temp1.end (); it1++){ Wu                              for(It2=temp2.begin (); It2!=temp2.end (); it2++){ -                                 if(*it1==*it2) { AboutTemp3.insert (*it1); $Temp2.erase (*it2); -                                      Break; -                                 } -                             } A                         } + S.push (ID (Temp3)); the                          Break; -                      Case 'A': $temp1=id_cache2[s.top ()]; the S.pop (); theTemp2=id_cache2[s.top ()]; the S.pop (); the Temp2.insert (ID (TEMP1)); - S.push (ID (TEMP2)); in                          Break; the                 } theCout<<id_cache2[s.top ()].size () <<Endl; About             } the         } the }; the  +  - intMain () { the     //freopen ("In.txt", "R", stdin);Bayi     intN; thescanf"%d",&n); the      while(n--){ - Love LIVE; - Live.start (); theprintf"***\n"); the     } the     return 0; the}

Uva 12096.The setstack Computer

Related Article

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.