1. 

/**
 * ACM Training 2009
 * ACM Problem #902 - Password Search
 * Link:
 *
 * @author Felix Dietrich
 * @version 1.0, 09/21/2009
 *
 * Methode: String Matching, HashMap
 * Status : Accepted
 * Runtime: 1.820
 */

import java.util.*;

public class Main
{
    public static void main(String... s)
    {
        Scanner sc = new Scanner(System.in);
        
        int passwordLength;
        int count;
        char[] message;
        StringBuilder possiblePW;
        String password;
        Map<String,Integer> pws = new HashMap<String,Integer>();
        
        while(sc.hasNext())
        {
            // init all
            passwordLength = sc.nextInt();
            possiblePW = new StringBuilder(passwordLength);
            message = sc.next().toCharArray();
            pws.clear();
            
            // start
            for(int i=0; i<passwordLength; i++)
                possiblePW.append(message[i]);
            
            for(int i=passwordLength; i<message.length; i++)
            {
                password = possiblePW.toString();
                if(pws.containsKey(password))
                    pws.put(password, pws.get(password)+1);
                else
                    pws.put(password, 1);
                possiblePW.deleteCharAt(0);
                possiblePW.append(message[i]);
            }
            
            password = possiblePW.toString();
            if(pws.containsKey(password))
                pws.put(password, pws.get(password)+1);
            else
                pws.put(password, 1);
            
            count = Collections.max(pws.values());
            for(Map.Entry<String, Integer> me: pws.entrySet())
                if(me.getValue() == count)
                {
                    System.out.println(me.getKey());
                    break;
                }
        }
    }
}

2.

/* Angewandte Mathematik, SS09, IFB 2C 
* ACM Problem #902 (Password Search)
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=843
*
* @author Dennis Wilfert
* @author Johann Studt
* @version 1.0, 04/05/2009
*
* Status : Accepted
* Runtime: 2.900
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class PasswordSearch {

public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

Scanner scanner = new Scanner(reader);

String line = null;
int number = 0;
int count;
// Laenge der aktuellen Zeile
int linelength;
// Position mit dem Substring der am meisten vorkommt
int pos = 0;

while (scanner.hasNext()){

//Sehen wie lang der Code ist
number = scanner.nextInt();
//String in dem der Code versteckt ist
line = scanner.next();


if(number<11 && number>0){

// Zeichen bbis zu dem in der for-Schleife gelesen wird
linelength = line.length()-number+1;

// Zaehler fuer den Substring der am meisen vorkommt
count = 1;

// Substring der am meisten vorkommt
//String out = line.substring(0, number);

// Hashtable in welcher der Substring und die Anzahl des vorkommens gespeichert wird
Hashtable<String, Integer> numbers = new Hashtable<String, Integer>();

for(int i = 0; i < linelength; i++){

// Aktueller Substring
String str = line.substring(i, i+number);

// Existiert der Substring schon, dann pruefen wie oft er vorkommt
if(numbers.containsKey(str)){

int num = numbers.get(str);

// Ist die Anzahl des vorkommens gleich der nummer des counters, dann um eins erhoehen und in str speichern
if(num == count){
count++;
pos = i;
}

// Substring in der Hashtable um 1 erhoehen
numbers.put(str, num+1);
}
// Existiert der Substring noch nicht, dann neu eintragen
else numbers.put(str, 1);
}

System.out.println(line.substring(pos, pos+number));
}

}

}

}

3.

/**
* ACM
* UVa Status: accepted
* Run Time: 0.810
* Category: Hashing
* @author Evgeni Pavlidis evgenipavlidis@yahoo.de
*/
#include <iostream>
#include <map>
#include <cmath>

#define DEBUG 0

#define chr(a) (a-'a'+1)

#define MAX_HASHING_SIZE 9124679
#define HASH_BASE 26


using namespace std;

static int n;
static string input;

static int saveMax,stop,tmp,savePos;
static int hash[MAX_HASHING_SIZE];



long long power(long b, int p)
{
if(p == 0)
return 1;
long long result = b;
for(int i=1; i < p; i++)
result *= b;

return result;
}

int main()
{

long long hashCode,c;
while((cin >> n) && (cin >> input))
{
saveMax = 1;
savePos = 1;
stop = input.length() - n + 1;
hashCode = 0;

// clear hash
for(int i=0; i < MAX_HASHING_SIZE;i++)
hash[i] = 0;

// calc first hash
for(int i=n-1; i >=0; i--)
hashCode += power(HASH_BASE,i)*chr(input[n-i-1]);

hash[hashCode % MAX_HASHING_SIZE]++;

// calc all other hashes
for(int i=1; i < stop; i++)
{
hashCode = (hashCode - chr(input[i-1])*power(HASH_BASE,n-1))*HASH_BASE + chr(input[i+n-1]);

if((tmp = ++hash[hashCode % MAX_HASHING_SIZE]) > saveMax)
{
saveMax = tmp;
savePos = i;
}
}
cout << input.substr(savePos,n) << endl;
}
}

4.

*

 * ACM Programming Contest
 * Problem: 902 (Password Search)
 * Status: Accepted
 * Language: ANSI C
 * Runtime: 0.124
 * Date: 2009-05-12 17:17:00
 * Author: Andreas Kunft
 */

#include <stdio.h>
#include <string.h>

#define HASHTABLE_SIZE 9124679
#define BASE 26

int subLength, pIndex;
char str[100000000];
int hashtable[HASHTABLE_SIZE];
unsigned long long save = 0, hash = 0;

long long power(int p) {
long long power = BASE;
for (pIndex = 1; pIndex < p; pIndex++)
power *= BASE;

return power;
}

int main() {
int max = 1;
int pos = 0;
int t, numberOfSubs;
while (scanf("%d %s", &subLength, str) == 2) {

char result[subLength];

memset(hashtable, 0, HASHTABLE_SIZE * sizeof(int));

numberOfSubs = strlen(str) - subLength + 1;

long long saveBase = power(subLength - 1);

int i;
for (i = 0; i < subLength; i++) {
hash += power(subLength - 1 - i) * str[i];
}
save = saveBase * str[0];
hashtable[hash % HASHTABLE_SIZE]++;

for (i = 1; i < numberOfSubs; i++) {
hash = ((hash - save) * BASE) + str[i + subLength - 1];
save = saveBase * str[i];

if ((t = ++hashtable[hash % HASHTABLE_SIZE]) > max) {
max = t;
pos = i;
}
}
memcpy(result, str + pos, subLength);
result[subLength] = '\0';
printf("%s\n", result);
max = pos = save = hash = 0;
}
return 0;
}