#C5369. Repeated Word Detector
Repeated Word Detector
Repeated Word Detector
You are given a conversation consisting of several sentences. For each test case, you are given two integers \(N\) and \(M\) where \(N\) is the threshold for word repetition and \(M\) is the number of sentences in the conversation. For each sentence, if any word (case-sensitive) is repeated more than \(N\) times in that sentence, print FLAG
for that test case; otherwise, print OK
.
Note: Each sentence is assumed to end with a period ('.'). When processing, ignore the trailing period. Words are separated by spaces and the matching is case-sensitive.
Example 1:
Input:
2 2 3 Hello Hello world. This is a test sentence. Goodbye Goodbye Goodbye friends. 1 2 Hey there this is a test. Hello Hello this is a flag test.Output:
FLAG FLAG
Example 2:
Input:
1 3 2 One two three. One two three One two.Output:
OK
inputFormat
The input is given via standard input and has the following format:
T N1 M1 sentence1,1 sentence1,2 ... sentence1,M1 N2 M2 sentence2,1 ... sentence2,M2 ... NT MT sentenceT,1 ... sentenceT,MT
Here, the first line contains the integer \(T\), the number of test cases. Each test case begins with two integers \(N\) and \(M\) separated by a space, followed by \(M\) sentences. Each sentence ends with a period.
outputFormat
For each test case, output a single line containing either FLAG
if any sentence in the test case contains a word repeated more than \(N\) times, or OK
otherwise. The outputs for different test cases should be printed on separate lines via standard output.
2
2 3
Hello Hello world.
This is a test sentence.
Goodbye Goodbye Goodbye friends.
1 2
Hey there this is a test.
Hello Hello this is a flag test.
FLAG
FLAG
</p>