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.