AcWing 771. 字符串中最长的连续出现的字符 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-18 05:05:17
,
所有人可见
,
阅读 291
Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
for (int i = 0; i < n; i ++)
{
String s = cin.next();
int count = 0;
char x = s.charAt(0);
for (int j = 0; j < s.length(); j ++)
{
int k = j;
while (k < s.length() && s.charAt(k) == s.charAt(j))
k ++;
if (k - j > count)
{
count = k - j;
x = s.charAt(j);
}
j = k - 1;
}
System.out.println (x + " " + count);
}
}
}