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 ( 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 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\n",mind);
}
return 0;
}

11661 - Burger Time?的更多相关文章

  1. UVA 557 Burger 排列组合递推

    When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party was held at t ...

  2. UVA 557 - Burger(概率 递推)

     Burger  When Mr. and Mrs. Clinton's twin sons Ben and Bill had their tenth birthday, the party was ...

  3. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. 「UVA557」 Burger(概率

    本题征求翻译.如果你能提供翻译或者题意简述,请 提交翻译 ,感谢你的贡献. 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 复制 3 6 10 256 输出样例# ...

  5. Burger King使用RayOnSpark进行基于实时情景特征的快餐食品推荐

    作者:Luyang Wang, Kai Huang, Jiao Wang, Shengsheng Huang, Jason Dai 基于深度学习的推荐模型已广泛应用于各种电商平台中,为用户提供推荐.目 ...

  6. ROS开源小车TurtleBot3详情介绍(Burger)

    您为什么要选择ROS开源智能小车 ROS(RobotOperating System,机器人操作系统)是目前世界上更主流更多人使用的的机器人开源操作系统.它可以提供操作系统应有的服务,包括硬件抽象,底 ...

  7. UVa 557 (概率 递推) Burger

    题意: 有两种汉堡给2n个孩子吃,每个孩子在吃之前要抛硬币决定吃哪一种汉堡.如果只剩一种汉堡,就不用抛硬币了. 求最后两个孩子吃到同一种汉堡的概率. 分析: 可以从反面思考,求最后两个孩子吃到不同汉堡 ...

  8. UVA557 汉堡 Burger

    题面 https://www.luogu.org/problemnew/show/UVA557 这里顺便整理一下二维格点随机游走问题. 遇到这种问题时,需注意分母的计算问题. 设x为起点到终点的距离. ...

  9. uva 557 Burger

    https://vjudge.net/problem/UVA-557 题意: n个人,n/2个牛肉煲,n/2个鸡肉堡 每次抛硬币,根据正反决定每个人吃什么汉堡 如果某一个汉堡被选完了,就不抛了 问最后 ...

随机推荐

  1. django笔记(二)

    Model many-to-many可以通过through来定义详细信息. 表结构: property django可以用F和Q来配合查找,F可以用于同一个model不同field之间进行比较,可以对 ...

  2. JQuery中两个ul标签的li互相移动实现方法

    这篇文章主要介绍了JQuery中两个ul标签的li互相移动实现方法,可实现ul标签中li标签内容相互替换的技巧,涉及jQuery操作页面元素的相关技巧,需要的朋友可以参考下 本文实例讲述了JQuery ...

  3. Vmware虚拟机下三种网络模式配置

    VMware虚拟机有三种网络模式,分别是Bridged(桥接模式).NAT(网络地址转换模式).Host-only(主机模式). VMware workstation安装好之后会多出两个网络连接,分别 ...

  4. Sql 参数的使用

    代码片段: a)声明实例 1.声明SQLCommand实例. SqlCommand cmd = new SqlCommand(); 2.声明SqlDataAdapter实例. SqlDataAdapt ...

  5. secureCRT登录不上ubuntu,Connection closed

    secureCRT登录不上ubuntu 1.第一个原因是sshd服务没开,或者防火墙没关.装好sshd并打开就好. http://www.cnblogs.com/mylinux/p/5101956.h ...

  6. Java 判断多级路径是否存在,不存在就创建

    第一种方案: /** * 是否创建目录 * @param path * @return */ public boolean isexitsPath(String path)throws Interru ...

  7. netbeans 将项目打包生成单个可执行的 jar

    原文:netbeans 打包生成 jar 文件页里找到build.xml文件,打开在</project>前 加入以下代码保存之 <target name="package- ...

  8. servlet的filter的使用

    一.概述 过滤器是servlet的一个重要特性,它提供一种机制,允许在过滤器中,即可以修改浏览器的请求信息,也可以对服务器处理后的响应信息进行修改. 一个过滤器是一个实现了Filter接口的java类 ...

  9. log翻硬币

    若果有一组硬币,(假定有十个),每一个硬币仅仅有两个面,正面用以表示.反面用零表示. 给定目标(初始状态)1111100000 正正正正正反反反反反 (目标状态)   1000011101 正反反反反 ...

  10. oracle exp实例

    exp nam/pwd@ip:1521:databasename  log=/tmp/export.log  file=/tmp/oracle_database.dmp ./exp cmsuser/x ...