import java util Scanner public class MinDist public static void main

 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
import java.util.Scanner;
public class MinDist {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String s=sc.nextLine();
int sa=0,sb=0,min=9999999,i,len=s.length(),fa=0,fb=0;
char a=sc.next().charAt(0),b=sc.next().charAt(0);
for (i=0;i<len;i++)
{
if(s.charAt(i)!=a)
{
sb++;
}
if(s.charAt(i)!=b)
{
sa++;
}
if(s.charAt(i)==a)
{
sa=0;
if(min>sb && fb>0)
min=sb;
sb++;
fa++;
}
if(s.charAt(i)==b)
{
if(min>sa && fa>0)
min=sa;
sb=0;
sa++;
fb++;
}
}
System.out.println(min);
}
}