mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-04 00:38:13 +08:00
38 lines
1.6 KiB
HTML
38 lines
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<h1>1005. Programming Pattern (35)</h1>
|
|
<div id="problemContent">
|
|
<p>
|
|
Programmers often have a preference among program constructs. For example, some may prefer "if(0==a)", while others may prefer "if(!a)". Analyzing such patterns can help to narrow down a programmer's identity, which is useful for detecting plagiarism.
|
|
</p>
|
|
<p>Now given some text sampled from someone's program, can you find the person's most commonly used pattern of a specific length?
|
|
</p>
|
|
<p><b>
|
|
Input Specification:
|
|
</b></p>
|
|
<p>
|
|
Each input file contains one test case. For each case, there is one line consisting of the pattern length N (1<=N<=1048576), followed by one line no less than N and no more than 1048576 characters in length, terminated by a carriage return '\n'. The entire input is case sensitive.
|
|
</p>
|
|
<p><b>
|
|
Output Specification:
|
|
</b></p>
|
|
<p>For each test case, print in one line the length-N substring that occurs most frequently in the input, followed by a space and the number of times it has occurred in the input. If there are multiple such substrings, print the lexicographically smallest one.
|
|
</p>
|
|
<p>
|
|
Whitespace characters in the input should be printed as they are. Also note that there may be multiple occurrences of the same substring overlapping each other.
|
|
</p>
|
|
<b>Sample Input 1:</b><pre>
|
|
4
|
|
//A can can can a can.
|
|
</pre>
|
|
<b>Sample Output 1:</b><pre>
|
|
can 4
|
|
</pre>
|
|
<b>Sample Input 2:</b><pre>
|
|
3
|
|
int a=~~~~~~~~~~~~~~~~~~~~~0;
|
|
</pre>
|
|
<b>Sample Output 2:</b><pre>
|
|
~~~ 19
|
|
</pre>
|
|
</div> |