hdu4662MU Puzzle

http://acm.hdu.edu.cn/showproblem.php?pid=4662

I+3*U模6为2或4的都可以 一个U相当于3个I  而I只能1-》2-》4-》8。。如此变换

 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<algorithm>

 5 using namespace std;

 6 char s[100010];

 7 int main()

 8 {

 9     int i,n;

10     cin>>n;

11     while(n--)

12     {

13         cin>>s;int a=0,b=0;

14         int k = strlen(s);

15         if(s[0]!='M')

16         {

17             puts("No");

18             continue;

19         }

20         if(strcmp(s,"MI")==0)

21         {

22             puts("Yes");

23             continue;

24         }

25         for(i = 1 ; i < k ; i++)

26         if(s[i]=='I') a++;

27         else if(s[i]=='U') b++;

28         else break;

29         if(i!=k)

30         {

31             puts("No");

32             continue;

33         }

34         int s = a+b*3;

35         if(s%6==2||s%6==4)

36         puts("Yes");

37         else

38         puts("No");

39     }

40     return 0;

41 }
View Code

 

你可能感兴趣的:(HDU)