编程介的小学生 2019-05-21 22:18 采纳率: 20.5%
浏览 139

颜色字符的匹配的问题的解决,怎么采用C程序的语言代码编写程序去实现的呢?

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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的