11661-Burger Time?

Source: Internet
Author: User

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;}

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.