Hdu1181 (deformation course) and hdu1181 deformation course

Source: Internet
Author: User

Hdu1181 (deformation course) and hdu1181 deformation course

Click Open Link

Problem Description er ...... in the deformation class, Harry encountered a little trouble, because he could not remember all the spells as Hermione could and turn a baseball into a hedgehog at will, but he found a unified rule of the deformation spell: if a word begins with A and ends with B, the role of a is to change object A to object B.
Harry has put all of his manipulations into a table. He wants you to help calculate whether he can complete the teacher's homework) to become a M (Mouse), you know, if he can't do it himself, he will have to ask Hermione and be forced to listen to a lot of good learning principles.
 
There are multiple groups of Input test data. Each group has multiple rows and one word in each row, which only contains lowercase letters. It is all the spells of Harry. The number 0 indicates that a group of input ends.
 
Output if Harry can complete his job, he will Output "Yes."; otherwise, he will Output "No." (do not ignore the full stop)
 
Sample Input
sosoonrivergoesthemgotmoonbeginbig0
 
Sample Output
Yes.

# Include <stdio. h> # include <string. h> char s [10000], p [10000]; int visit [10000], sign, k; void DFS (int x) {int I; if (p [x] = 'M') {sign = 1; return ;}for (I = 0; I <k; I ++) if (visit [I] = 0 & s [I] = p [x]) // This word can be concatenated into multiple words, but the beginning and end of multiple words must be the same {visit [I] = 1; DFS (I); visit [I] = 0; if (sign) return ;}} int main () {char a [10000]; int I, t; while (scanf ("% s", )! = EOF) {k = 0; while (a [0]! = '0') {s [k] = a [0]; t = strlen (a); p [k] = a [T-1]; scanf ("% s ", a); k ++;} sign = 0; memset (visit, 0, sizeof (visit); for (I = 0; I <k; I ++) if (s [I] = 'B') {visit [I] = 1; DFS (I);} if (sign) printf ("Yes. \ n "); else printf (" No. \ n ") ;}return 0 ;}





Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.