编程介的小学生 2017-11-04 10:21 采纳率: 20.5%
浏览 1043
已采纳

Greed is good

Problem Description
As we all know Uncle CTW is a very greedy uncle,he likes collecting jewels.One day he gets a necklace with beautiful gems,he has a strange habit,that he only collects the contiguous gems with with same color.That means if he pick a red gem at first,and he will continue to pick only if the next gem is red,or he will stop.(That's why people call him "Uncle.Strange").
As it is a necklace,he must find somewhere to cut the necklace at the very begining,then select an end to pick until meet a different color gem,and do the same for the other end (which might not be of the same color as the gems collected before this).
There are only three kinds of gems,red('r'),pink('p'),and white('w'),and NOTICE that,because the white one could be painted,so it can be seen as either color.(See the sample for detail.)
Now he just want to know the maximum number of gems he can collect,could you tell him?

Input
The first line contain an integer T,then T lines,each line with a string only contain r,p or w ,with length no more than 400.

Output
One integer per line indicating the maximum nunber.

Sample Input
1
wwwpprwrprprrprprwrwwrpwrwrrp

Sample Output
11

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示