Burger Time? Everybody knows that along the more important highways there are countless fast food serving ants. one can find easily hamburgers, hot dogs, pizzas, sandwiches... food everywhere. couldn't find a restaurant but a drugstore. after a big lunch with fast food it's normal that we need a drugstore because our stomach begins to feel pain. given the locations of the specified ants and drugstores on a highway, you want to determine the minimum distance between a restaurant and a drugstore. input The first line of each test case gives an integer L (1 L 2000000) indicating the length of the highway. the second line of each test case contains a string S of length L, showing the positions of the specified ants and drugstores along the highway in the following manner: the character ''r'' represents a place with a restaurant. the character ''d' represents a place with a drugstore. the character ''z'' represents a place with a restaurant and a drugstore. the character ''. ''represents an empty place. you can suppose that every test case has at least one restaurant and at least one drugstore. the end of the input is indicated when L = 0. output For each case in the input, print one line with the minimum distance between a restaurant and a drugstore. sample Input 2RD5 .. Z .. 10. R ...... d.10.R .. z... d.10... D .. r... 25 .. d... r. RR... DD... d. r... r0Sample Output 107032
#include<cstdio>#include<algorithm>using namespace std;char a[2000005];int main(){int n,i,j;while(scanf("%d",&n)&&n){int mind=2000005,j=0;scanf("%s",a);for(i=0;i<n;i++){if(a[i]=='Z') mind=0;if(a[i]!='.'){if(a[j]!='.'&&a[i]!=a[j])mind=min(mind,i-j);j=i;}}printf("%d\n",mind);}return 0;}