1.

/**
* ACM Training
* ACM Problem: Contest Problem: F - Burger Time?
* Link: http://uva.onlinejudge.org/contests/235-f0e63531/11646.html
* @author Miesel Christoph
* @version 1.0 22.08.2009
* Status : Accepted
* Runtime: 0.720
*/

import java.util.*;

public class BurgerTime
{
public static final char z = 'Z';

private static boolean dActive, rActive;

private static void isActive(char ch)
{
if(ch == 'D')
dActive = true;
if(ch == 'R')
rActive = true;
}

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

int L, length;
String s;
int DR = 0, RD = 0;
char tmp;

while((L = sc.nextInt()) != 0)
{
dActive = false;
rActive = false;
DR = 0;
RD = 0;
length = Integer.MAX_VALUE;
s = sc.next();

for(int i = 0; i < L; i++)
{
tmp = s.charAt(i);
if(!(tmp == '.'))
{
if(tmp == z)
{
length = 0;
break;
}
else
{
if(tmp == 'D')
{
if(!dActive)
isActive('D');
else
DR = 0;

if(rActive)
{
RD++;
length = length < RD ? length : RD;
RD = 0;
rActive = false;
}


}

if(tmp == 'R')
{
if(!rActive)
isActive('R');
else
RD = 0;

if(dActive)
{
DR++;
length = length < DR ? length : DR;
DR = 0;
dActive = false;
}
}
}
}
else
{
if(rActive)
RD++;
if(dActive)
DR++;
}
}
System.out.println(length);
}
}
}

2.

import java.io.*;
import java.util.*;

/**
* ACM Training 2009
* ACM Problem #11661 - Burger Time?
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2708
*
* @author Felix Dietrich
* @version 1.0, 09/26/2009
*
* Methode: Shortest subsequence
* Status : Accepted
* Runtime: 1.424
*/
public class Main
{
public static void main(String... args) throws NumberFormatException, IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

while (true)
{
///////////////
//READ INFO
int length = Integer.parseInt(br.readLine());

if (length == 0)
return;

char[] highway = br.readLine().trim().toCharArray();
int restaurantIndex = -1;
int drugStoreIndex = -1;
List<Integer> allDistances = new ArrayList<Integer>();

////////////
// CALC

for (int i=0; i<highway.length; i++)
{
// always 0
if(highway[i] == 'Z')
{
restaurantIndex = -2;
break;
}

// add new distance if we already found a drug store
if(highway[i] == 'R')
{
restaurantIndex = i;
if(drugStoreIndex != -1)
allDistances.add(Math.abs(restaurantIndex-drugStoreIndex));
}

// add new distance if we already found a restaurant
if(highway[i] == 'D')
{
drugStoreIndex = i;
if(restaurantIndex != -1)
allDistances.add(Math.abs(restaurantIndex-drugStoreIndex));
}
}

// if there was a Z in the input, we dont need to travel at all
if(restaurantIndex == -2)
{
System.out.println(0);
}
else
{
// sort all distances and print the shortest
Collections.sort(allDistances);
System.out.println(allDistances.get(0));
}
}
}
}


3.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/**
* ACM Training 2009
* ACM Problem #11661 - Burger Time?
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2708
*
* @author Dennis Wilfert
* @version 1.0, 09/06/2009
*
* Status : Accepted
* Runtime: 0.256
*/
public class BurgerTime {

public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

int length = Integer.parseInt(reader.readLine());
char[] street;
int shortest, temp;
char last = 0;
while (length != 0) {

street = reader.readLine().toCharArray();
shortest = temp = 0;
last = 0;

for (char c : street) {

if (c == '.') {
temp++;
}
else{
if (c == 'Z') {
shortest = 0;
break;
}
if (last != c && last != 0) {
temp++;
if ((temp < shortest) || (shortest == 0)) {
shortest = temp;
}
}
last = c;
temp = 0;
}
}
writer.println(shortest);

length = Integer.parseInt(reader.readLine());
}
writer.flush();
}
}