Spit Bubble (2018 National multi-school algorithm winter training Camp Practice Competition (second) + stack Simulation) +plug-in (codeforces81a+ stack simulation)

Source: Internet
Author: User
Tags acos bitset cmath

Spit Bubble Topic Link:https://www.nowcoder.com/acm/contest/74/A

Topic:

Ideas:
This topic was stuck to me for a long time, today morning training encountered a problem, one eye on the idea of a stack simulation, and then back to the problem. The problem is very simple, look at the code basically can understand, do not explain.

The code is implemented as follows:

1#include <Set>2#include <map>3#include <queue>4#include <stack>5#include <cmath>6#include <bitset>7#include <cstdio>8#include <string>9#include <vector>Ten#include <cstdlib> One#include <cstring> A#include <iostream> -#include <algorithm> - using namespacestd; the  -typedefLong Longll; -typedef PAIR&LT;LL, Ll>PLL; -typedef PAIR&LT;LL,int>Pli; +typedef pair<int, ll>pil;; -typedef pair<int,int>PII; +typedef unsignedLong Longull; A  at #defineLson i<<1 - #defineRson i<<1|1 - #defineLowbit (x) x& (-X) - #defineBug printf ("*********\n"); - #defineDebug (x) cout<< "[" <<x<<] "<<endl; - #defineFIN freopen ("D://code//in.txt "," R ", stdin); in #defineIO Ios::sync_with_stdio (False), Cin.tie (0); -  to Const DoubleEPS = 1e-8; + Const intMoD = 1e9 +7; - Const intMAXN = 1e6 +7; the Const DoublePI = ACOs (-1); * Const intINF =0x3f3f3f3f; $ Constll INF =0x3f3f3f3f3f3f3f3f;Panax Notoginseng  - Chars[ the]; thevector<Char>v; +stack<Char>p; A  the intMain () { +      while(~SCANF ("%s", s)) { - v.clear (); $          while(!p.empty ()) P.pop (); $         intLen =strlen (s); -          for(inti =0; i < Len; i++) { -             if(P.empty ()) { the P.push (S[i]); -                 Continue;Wuyi             } the             if(P.top () = ='o'&& S[i] = ='o') { - P.pop (); Wu                 if(P.empty () | | p.top ()! ='O') { -P.push ('O'); About}Else { $ P.pop (); -                 } -}Else if(S[i] = ='O'&&!p.empty () && p.top () = ='O') { - P.pop (); A                 Continue; +}Else { the P.push (S[i]); -             } $         } the          while(!P.empty ()) { the V.push_back (P.top ()); the P.pop (); the         } - Reverse (V.begin (), V.end ()); in          for(inti =0; I < v.size (); i++) { theprintf"%c", V[i]); the         } Aboutprintf"\ n"); the     } the     return 0; the}

plug-in topic Link:Http://codeforces.com/problemset/problem/81/A

Topic:

Test instructions

  Give you a string, if the next two letters are the same, then the two letters will be eliminated, if the elimination of a few letters and then there are two letters adjacent to continue to erase.

Ideas:

  Ditto.

The code is implemented as follows:

  

1#include <Set>2#include <map>3#include <queue>4#include <stack>5#include <cmath>6#include <bitset>7#include <cstdio>8#include <string>9#include <vector>Ten#include <cstdlib> One#include <cstring> A#include <iostream> -#include <algorithm> - using namespacestd; the  -typedefLong Longll; -typedef PAIR&LT;LL, Ll>PLL; -typedef PAIR&LT;LL,int>Pli; +typedef pair<int, ll>pil;; -typedef pair<int,int>PII; +typedef unsignedLong Longull; A  at #defineLson i<<1 - #defineRson i<<1|1 - #defineLowbit (x) x& (-X) - #defineBug printf ("*********\n"); - #defineDebug (x) cout<< "[" <<x<<] "<<endl; - #defineFIN freopen ("D://code//in.txt "," R ", stdin); in #defineIO Ios::sync_with_stdio (False), Cin.tie (0); -  to Const DoubleEPS = 1e-8; + Const intMoD = 1e9 +7; - Const intMAXN = 2e5 +7; the Const DoublePI = ACOs (-1); * Const intINF =0x3f3f3f3f; $ Constll INF =0x3f3f3f3f3f3f3f3f;Panax Notoginseng  - CharS[MAXN]; thevector<Char>v; +stack<Char>Q; A  the intMain () { +scanf"%s", s); -Q.push (s[0]); $     intLen =strlen (s); $      for(inti =1; i < Len; i++) { -         if(Q.empty ()) {Q.push (s[i]);Continue;} -         if(S[i] = =Q.top ()) { the Q.pop (); -}Else {Wuyi Q.push (S[i]); the         } -     } Wu      while(!Q.empty ()) { - V.push_back (Q.top ()); About Q.pop (); $     } - Reverse (V.begin (), V.end ()); -      for(inti =0; I < v.size (); i++) { -printf"%c", V[i]); A     } +printf"\ n"); the     return 0; -}

Spit Bubble (2018 National multi-school algorithm winter training Camp Practice Competition (second) + stack Simulation) +plug-in (codeforces81a+ stack simulation)

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.