Introductory Classics-Basic data Structure topics (List)

Source: Internet
Author: User
Tags cmath

UVA127

Links: Https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem =63

A very good simulation of the stack, training plans to push back a week, because of various things, but they have made the changes, but also say, tonight, the bedroom two God is not in, rare mood good,

The problem is actually read the code of others, Daniel Blog: http://blog.csdn.net/hyczms/article/details/38009937

My Code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <cmath>6#include <vector>7#include <stack>8#include <algorithm>9 using namespacestd;Ten Const intmaxn= Wu; One structCard A { -     CharValue,suit; - }; the intjudge (Card X,card y) - { -     return(x.value==y.value| | x.suit==y.suit); - } + intMain () - { +Stack<card>S[MAXN]; A card card; at     intn=0, I; -      while(SCANF ("%c%c", &card.value, &card.suit) && card.value! ='#') -     { - GetChar (); -s[n++].push (card); -         if(n== the) in         { -             intm=1, Flag; to              while(true) +             { -                  for(i=m;i<n;i++) the                 { *                     if(i>=3&&judge (S[i].top (), s[i-3].top ())) $                     {Panax Notoginsengflag=1; -                          Break; the                     } +                     Else if(i>=1&&judge (S[i].top (), s[i-1].top ())) A                     { theflag=2; +                          Break; -                     } $                 } $                 if(i==N) -                      Break; -                 if(flag==1) the                 { -s[i-3].push (S[i].top ());Wuyim=i-3; the                 } -                 Else Wu                 { -s[i-1].push (S[i].top ()); Aboutm=i-1; $                 } - S[i].pop (); -                 if(S[i].empty ()) -                 { A                      for(intj=i;j<n-1; j + +) +s[j]=s[j+1]; the                      while(!s[n-1].empty ()) -s[n-1].pop (); $n--; the                 } the             } the             if(n>1) theprintf"%d piles remaining:", n); -             Else inprintf"%d pile remaining:", n); the              for(intI=0; i<n;i++) the             { Aboutprintf"%d", S[i].size ()); the                  while(!s[i].empty ()) the S[i].pop (); the             } +printf"\ n"); -n=0; the         }Bayi     } the     return 0; the}
View Code

Start to brush the first day of the problem, but also just use the night to review the time to go back to the bedroom to do their favorite things, hope can persist

UVA673

Links: Https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=103&page=show_ problem&problem=614

The classic topic of a stack

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <cmath>6#include <vector>7#include <stack>8#include <algorithm>9#include <cctype>Ten#include <cstdlib> One using namespacestd; A Const intmaxn= -+Ten; - //Char S[MAXN]; - intMain () the { -     intT; -Cin>>T; - getc (stdin); +      while(t--) -     { +         CharS[MAXN]; A gets (s); atstack<Char>A; -         intstr1=']'-'['; -         intStr2=')'-'('; -         intn=strlen (s); -          for(intI=0; i<n;i++) -         { in             if(A.empty ()) -             { to A.push (S[i]); +                 Continue; -             } the             Chart=a.top (); *             if(s[i]-t==str1| | s[i]-t==str2) $ A.pop ();Panax Notoginseng             Else - A.push (S[i]); the         } +         if(A.empty ()) Acout<<"Yes"<<Endl; the         Else +cout<<"No"<<Endl; -     } $     return 0; $}
View Code

Introductory Classics-Basic data Structure topics (List)

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.