将U全部转化为I 因为 I 的个数一定是2的n次方 有可能消除了一定数量的 2U 所以I的个数加上一个6的整数倍是2的n次方
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[1000010];
int b[40] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824};
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
int len = strlen(a);
int sum = 0;
if(a[0] == 'M')
{
int flag = 0,flag2 = 0;
for(int i = 1; i < len; i++)
{
if(a[i] == 'I')
{
sum++;
}
else if(a[i] == 'U')
{
sum += 3;
}
else
{
flag2 = 1;
break;
}
}
if(!flag2)
{
for(int i = 0; i <= 29; i++)
{
if(b[i] >= sum && (b[i]-sum) % 6 == 0)
{
flag = 1;
break;
}
}
if(flag)
puts("Yes");
else
puts("No");
}
else
puts("No");
}
else
puts("No");
}
return 0;
}