LSS

Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others)

Problem Description

Time flies, four years passed, colleage is over. When I am about to leave, a xuemei ask me an ACM  problem, but I can't solve it, I am 功力尽失.  Please help me so that I won't lose face in front of xuemei!

Give you a string , you should find the longest substring which is of the same character.

Input

First line there is a T , represents the test cases.

next T lines  will be T strings.

the length of every string is less than 100

all the characters of the strings will be lowercase letters

Output

for each test case output a number

Sample Input

1
a

Sample Output

1

Source

wuyiqi

Manager

 
  水题,求最长连续相同字符子串长度。
  就这么道破题纠结了我和旭旭一晚上,啊啊啊,脑子抽抽了,真不应该。无法很好的理解题意是大问题啊。这道题坑就坑在题目中提到的“字串”的含义应该是连续的,而我理解的字串应该是不连续的啊!像最长公共字串问题里面的字串不就是不连续的吗,有点凌乱了…… 总之卡在这么道题上,真给跪了,怨念无穷啊……
  题意:求最长连续相同字符子串长度。
  思路:从a[1]开始比较,每一个字符与它前面的字符比较如果相同,num加1,每次与sum比较,如果num>sum,令sum=num。最后输出sum。
  代码
 #include <iostream>

 using namespace std;

 int main()
{
int T,i;
cin>>T;
while(T--){
char a[];
cin>>a;
//统计最长连续相同字符子串长度
int num=,sum=;
for(i=;a[i];i++){
if(a[i]==a[i-])
num++;
else
num=;
if(num>sum)
sum=num;
}
cout<<sum<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

Acdream 1111:LSS(水题,字符串处理)的更多相关文章

  1. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  2. ytu 1064: 输入三个字符串,按由小到大的顺序输出(水题,字符串处理)

    1064: 输入三个字符串,按由小到大的顺序输出 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 471  Solved: 188[Submit][Sta ...

  3. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  4. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  5. ytu 1052: 写一函数,将两个字符串连接(水题,指针练习)

    1052: 写一函数,将两个字符串连接 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 343  Solved: 210[Submit][Status][ ...

  6. 1222: FJ的字符串 [水题]

    1222: FJ的字符串 [水题] 时间限制: 1 Sec 内存限制: 128 MB 提交: 92 解决: 20 统计 题目描述 FJ在沙盘上写了这样一些字符串: A1  =  “A” A2  =   ...

  7. 1001 字符串“水”题(二进制,map,哈希)

    1001: 字符串“水”题 时间限制: 1 Sec  内存限制: 128 MB提交: 210  解决: 39[提交][状态][讨论版] 题目描述 给出一个长度为 n 的字符串(1<=n<= ...

  8. 暑假训练Round1——G: Hkhv的水题之二(字符串的最小表示)

    Problem 1057: Hkhv的水题之二 Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format: ...

  9. sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

    n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you w ...

随机推荐

  1. Hello 2016

    Hello 2016 I am really happy to work and study here. Nothing is better than be oneself ! It's import ...

  2. linux系统vsftpd登陆慢卡怎么办

    linux系统vsftpd登陆慢卡怎么办 浏览:145 | 更新:2013-12-31 00:50 vsftpd是linux系统中的一款ftp软件,用它可以实现文件,数据上传与下载,但有些用户会发现v ...

  3. ubuntu14.04 server安装vncserver

    $ sudo apt-get install -y tightvncserver $ vncserver 转自: https://www.liquidweb.com/kb/how-to-install ...

  4. 【GoLang】类型和作用在它上面定义的方法必须在同一个包里定义

    cannot define new methods on non-local type int 参考资料: http://wiki.jikexueyuan.com/project/the-way-to ...

  5. VirtualBox中安装Ubuntu12.04/Ubuntu14.04虚拟机

    NOTE: 一开始安装的Ubuntu12.04,后来又重新安装了14.04.截图基本使用了安装12.04时的截图,后来安装14.04时又补充了几张.该安装过程对Ubuntu12.04和14.04都是适 ...

  6. [k]自定义上传文件按钮样式

    <!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title> ...

  7. Flatten 2D Vector

    Implement an iterator to flatten a 2d vector. For example, Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  8. ERROR Cannot determine the location of the VS Common Tools Folder

    参考:ERROR Cannot determine the location of the VS Common Tools Folder   http://blog.csdn.net/m3728975 ...

  9. MDI窗体

    1.设置父窗体 使用MDI窗体,需要先将父窗体的IsMdiContainer属性设置为True 2.生成用于MDI子窗体的窗体 1 frmTemp f1 = new frmTemp(); f1.Tex ...

  10. linux skill

    linux console终端乱码解决 1.console终端乱码 在/etc/profile文件的最后一行添加如下内容: export LC_ALL="zh_CN.GB18030" ...