posts - 20,  comments - 6,  trackbacks - 0
  1#include<stdio.h>
  2#include<string.h>
  3int main()
  4{
  5    char nek[1000],bf[1000];
  6    int i,j,l,k;
  7    int as,bs,c1,c2;
  8    int ap,bp;
  9    int max;
 10    int t;
 11    
 12    while(scanf("%d",&t)!=EOF)
 13    {
 14        while(t--)
 15        {
 16            max=0;
 17            as=0;
 18            bs=1;
 19            scanf("%s",nek);
 20            strcpy(bf,nek);
 21            l=strlen(nek);
 22            while(bs<l)
 23            {
 24                ap=bp=0;
 25                c1=0;
 26                c2=0;
 27                for(i=as;;i--)
 28                {
 29                    if(i<0)
 30                    {
 31                        i=l-1;
 32                    }

 33                        if(nek[i]=='a')
 34                        break;
 35                    if(nek[i]=='w')
 36                        {
 37                            nek[i]='a';
 38                            c1++;
 39                        }

 40                        if(nek[i]=='p')
 41                        {
 42                            if(ap==0||ap==1)
 43                            {
 44                                nek[i]='a';
 45                            ap=1;
 46                            c1++;
 47                            }
else
 48                                break;
 49                                
 50                        }

 51                        if(nek[i]=='r')
 52                        {
 53                            if(ap==0||ap==2)
 54                            {
 55                                nek[i]='a';
 56                            ap=2;
 57                            c1++;
 58                            }
else
 59                            break;
 60                        }

 61                    
 62                            
 63                }

 64                for(j=bs;;j++)
 65                {
 66                    if(j==l)
 67                    {
 68                        j=0;
 69                    }

 70                        if(nek[j]=='a')
 71                        break;
 72                        if(nek[j]=='w')
 73                        {
 74                            nek[j]=='a';
 75                            c2++;
 76                        }

 77                        if(nek[j]=='p')
 78                        {
 79                            if(bp==0||bp==1)
 80                            {nek[j]=='a';
 81                            bp=1;
 82                            c2++;
 83                            }

 84                            else
 85                            break;                            
 86                        }

 87                        if(nek[j]=='r')
 88                        {
 89                            if(bp==0||bp==2)
 90                            {nek[j]=='a';
 91                            bp=2;
 92                            c2++;
 93                            }

 94                            else
 95                            break;
 96                        }

 97                    
 98    
 99                }

100                if(max<c1+c2)
101                {
102                    max=c1+c2;
103                }

104                strcpy(nek,bf);
105                c1=c2=0;
106                ap=bp=0;
107                as++;
108                bs++;
109            }

110                c1=c2=0;
111                ap=bp=0;
112                as=bs=1;
113                for(i=l-1,j=0;i>j;i--,j++)
114                {
115                    if(nek[i]=='w'&&as)
116                    {
117                        c1++;
118                    }

119                    if(nek[j]=='w'&&bs)
120                    {
121                        c2++;
122                    }

123                    if(nek[i]=='p'&&as)
124                    {
125                        if(ap==0||ap==1)
126                        {
127                        ap=1;
128                        c1++;
129                        }
else
130                        {as=0;
131                        }

132                    }

133                    if(nek[j]=='p'&&bs)
134                    {
135                        if(bp==0||bp==1)
136                        {
137                        bp=1;
138                        c2++;
139                        }
else
140                        {
141                            bs=0;
142                        }

143                    }

144                    if(nek[i]=='r'&&as)
145                    {
146                        if(ap==0||ap==2)
147                        {
148                        ap=2;
149                        c1++;
150                        }
else
151                        as=0;
152                    }

153                    if(nek[j]=='r'&&bs)
154                    {
155                        if(bp==0||bp==2)
156                        {
157                        bp=2;
158                        c2++;
159                        }
else
160                        {
161                            bs=0;
162                        }

163                    }

164                }

165                if(max<c1+c2)
166                {
167                    max=c1+c2;
168                }

169                printf("%d\n",max);
170        }

171    }

172}

173                
174            
posted on 2009-01-27 14:03 混沌的云 阅读(115) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


<2009年1月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

常用链接

留言簿(1)

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜