暴力模拟

细节处理很重要。。。

 

  1 #include <iostream>
  2 #include <cstring>
  3 #include <cstdio>
  4 using namespace std;
  5 
  6     char s1[100],s[100];
  7         int len1,len;
  8     int t;
  9     char a[55],b[55],c[55];
 10     
 11 int solved1 (int l,int len){
 12     int temp=0,j;
 13     for (int i=1;i*3<=len;i++){
 14         if ((len-i*3)%2||len<=i*3)
 15             continue ;
 16         j=(len-i*3)/2;
 17         if (i==j){
 18             int flag=1;
 19             for (int z=0;z<i;z++)
 20                 if (s[l+z]!=s[l+z+i]){
 21                     flag=0;
 22                     break ;
 23                 }
 24             if (flag)
 25                 continue ;
 26         }
 27         temp=1;
 28         for (int z=0;z<i+j+i;z++)
 29             if (s[l+z]!=s[l+z+i+j]){
 30                 temp=0;
 31                 break ;
 32             }
 33         if (temp)
 34             return temp;
 35     }
 36     return temp;
 37 }
 38 int solved2 (int l,int len){
 39     int temp=0;
 40     int j,k;
 41     for (int i=1;i*3<=len;i++){
 42         for (int j=1;(j+i)*3<=len;j++){
 43             if (len<=(i+j)*3)
 44                 continue ;
 45             if (i==j){
 46                 int flag=1;
 47                 for (int z=0;z<i;z++)
 48                     if (s[l+z]!=s[l+z+i]){
 49                         flag=0;
 50                         break ;
 51                     }
 52                 if (flag)
 53                     continue ;
 54             }
 55             k=len-3*(i+j);
 56             if (k==i){
 57                 int flag=1;
 58                 for (int z=0;z<i;z++)
 59                     if (s[l+z]!=s[l+z+i+i+j+j]){
 60                         flag=0;
 61                         break ;
 62                     }
 63                 if (flag)
 64                     continue ;
 65             }
 66             if (k==j){
 67                 int flag=1;
 68                 for (int z=i;z<i+j;z++)
 69                     if (s[l+z]!=s[l+z+j+i+j]){
 70                         flag=0;//cout<<z<<" "<<z+k<<endl;
 71                         break ;
 72                     }
 73                 if (flag)
 74                     continue ;
 75             }
 76             temp=1;
 77             for (int z=0;z<i+j;z++)
 78                 if (s[l+z]!=s[l+z+i+j]||s[l+z]!=s[l+z+i+j+i+j+k]){
 79                     temp=0;
 80                     break ;
 81                 }
 82             if (temp)
 83                 return temp;
 84         }
 85     }
 86     return temp;
 87 }
 88 
 89 int solved (){
 90     return solved1(0,len)+solved2(0,len);
 91 }
 92 
 93 int main (){
 94     cin>>t;
 95     while (t--){
 96         //cin.ignore ();
 97         cin>>s1;
 98         len1=strlen (s1);
 99         len=0;
100         memset (s,'\0',sizeof s);
101         for (int i=0;i<len1;i++)
102             if ((s1[i]>='a'&&s1[i]<='z')||(s1[i]>='A'&&s1[i]<='Z')){
103                 s[len++]=s1[i];
104             }//cout<<len<<" "<<s<<endl;
105             //if (solved1()) cout<<"1"<<endl;
106         if (solved())
107             printf ("Yes\n");
108         else printf ("No\n");
109     }
110     return 0;
111 }

 

posted on 2014-09-11 23:04  gfc  阅读(138)  评论(0编辑  收藏  举报