-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathWORDCNT.cs
48 lines (43 loc) · 1.27 KB
/
WORDCNT.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
// https://www.spoj.com/problems/WORDCNT/ #ad-hoc
// Finds the longest contiguous sequence of words of the same length.
public static class WORDCNT
{
public static int Solve(string[] words)
{
int longestSequenceLength = 0;
int currentSequenceLength = 0;
int previousWordLength = -1;
foreach (string word in words)
{
if (word.Length == previousWordLength)
{
++currentSequenceLength;
}
else
{
if (currentSequenceLength > longestSequenceLength)
{
longestSequenceLength = currentSequenceLength;
}
currentSequenceLength = 1;
previousWordLength = word.Length;
}
}
return Math.Max(longestSequenceLength, currentSequenceLength);
}
}
public static class Program
{
private static void Main()
{
int remainingTestCases = int.Parse(Console.ReadLine());
while (remainingTestCases-- > 0)
{
string[] words = Console.ReadLine().Split(
default(char[]),StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(
WORDCNT.Solve(words));
}
}
}