HDU 1181-Metamorphosis Course

Source: Internet
Author: User

Problem Description uh ... In the Metamorphosis class Harry ran into a little trouble, because he was not as Hermione as he could remember all the spells and randomly turned a baseball into a hedgehog or something, but he found a uniform rule of Transfiguration spells: If the spell is a word ending with a B, Then it works just to make a object into a B object.
Harry has already made a list of all the spells he has, and he wants you to help calculate whether he can finish the teacher's homework and turn a B (ball) into a M (Mouse), you know, if he can't do it himself, he has to ask Hermione. and was forced to listen to a lot of good learning. There are multiple sets of input test data. Each group has multiple lines, one word per line, and only lowercase letters, all of Harry's spells. The number 0 indicates the end of a set of inputs. Output "Yes" If Harry can finish his homework, or output "No." (Do not ignore the period) Sample inputsosoonrivergoesthemgotmoonbeginbig0sample Outputyes. HintHintharry can read this mantra: "Big-got-them".

Problem Solving Ideas:

DFS, pay attention to the restoration of node flag, as well as the very pit Dad's multi-group test ! (The Sound of WA is a piece of-.-)

1#include <iostream>2#include <cstring>3#include <string>4#include <algorithm>5 using namespacestd;6 stringb;7 Charlef[ +],rig[ +];8 intflag[ +];9 intnum;Ten BOOLans; One voidSrhCharx) A { -     for(intI=1; i<=num;i++) -    { the         if(lef[i]==x&&flag[i]==0) -         { -             if(rig[i]=='m') -             { +ans=1; -                  Break; +             } A             Else at             { -flag[i]=1; - SRH (Rig[i]); -flag[i]=0; -             } -         } in    } - } to intMain () + { -      while(cin>>b) the     { *ans=0; $num=1;Panax Notoginsengmemset (LEF,0,sizeof(LEF)); -memset (Flag,0,sizeof(flag)); thelef[1]=b[0]; +rig[1]=b[b.length ()-1]; A          for(intI=2;; i++) the         { +Cin>>b; -             if(b[0]=='0') Break; $lef[i]=b[0]; $Rig[i]=b[b.length ()-1]; -num++; -         } the          for(intI=1; i<=num;i++) -         {Wuyi             if(ANS) Break; the             if(lef[i]=='b'&&flag[i]==0) -                 if(rig[i]=='m') Wu                 { -ans=1; About                      Break; $                 } -                 Else -                 { -flag[i]=1; A SRH (Rig[i]); +flag[i]=0; the                 } -      $         } the         if(ANS) cout<<"Yes."<<Endl; the         Elsecout<<"No."<<Endl; the     } the}

HDU 1181-Metamorphosis Course

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.