zoukankan      html  css  js  c++  java
  • 11661


      Burger Time? 

    Everybody knows that along the more important highways there are countless fast food restaurants. One can find easily hamburgers, hot dogs, pizzas, sandwiches ... food everywhere.

    Many times the problem isn't to 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 restaurants 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 ( $ leq$ L $ leq$ 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 restaurants 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 

     

    2
    RD
    5
    ..Z..
    10
    .R......D.
    10
    .R..Z...D.
    10
    ...D..R...
    25
    ..D...R.RR...DD...D.R...R
    0
    

     

    Sample Output 

     

    1
    0
    7
    0
    3
    2
    

     

    #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
    ",mind);
    	}
    	return 0;
    }
  • 相关阅读:
    使用 UDDI 的 Web 服务描述和发现(第一部分) 沧海
    软件配置管理(SCM) 沧海
    什么是WebService 沧海
    WSDL概述 沧海
    分析:对QQ、ICQ发展前景的判断 沧海
    软件巨头的高校人才之争 沧海
    读“我为什么不要应届毕业生” 沧海
    IT监控工作如何引入热门的ITIL? 沧海
    IT项目管理向沟通要效率 沧海
    闫成印:证券信息化未来需求分析 沧海
  • 原文地址:https://www.cnblogs.com/james1207/p/3301796.html
Copyright © 2011-2022 走看看