zoukankan      html  css  js  c++  java
  • SPOJ 10234. Here Be Dragons

    The Triwizard Tournament's third task is to negotiate a corridor of many segments, and reach the other end. The corridor is N segments long. The ith segment is either empty or has a dragon. Harry cannot pass the dragon and will have no option but to retreat if he encounters one. Is it possible for him to reach the exit starting from the entrance?

    Input (STDIN):
    The first line contains the number of test cases T.
    Each of the next T lines contains a string describing the corridor. The ith character is either a '.' if the segment is empty, or a 'D' if the segment contains a dragon.
    Output (STDOUT):
    Output T lines, each containing either the string "Possible" if you can reach the exit, and "You shall not pass!" if it is not possible to reach the exit.
    Constraints:
    1 <= T <= 50
    1 <= N <= 50
    Time Limit: 1 s
    Memory Limit: 32 MB
    Sample Input:
    3
    ..
    ..D.
    D..D
    Sample Output:
    Possible
    You shall not pass!
    You shall not pass!

    The Triwizard Tournament's third task is to negotiate a corridor of many segments, and reach the other end. The corridor is N segments long. The ith segment is either empty or has a dragon. Harry cannot pass the dragon and will have no option but to retreat if he encounters one. Is it possible for him to reach the exit starting from the entrance?

    Input (STDIN):

    The first line contains the number of test cases T.

    Each of the next T lines contains a string describing the corridor. The ith character is either a '.' if the segment is empty, or a 'D' if the segment contains a dragon.

    Output (STDOUT):

    Output T lines, each containing either the string "Possible" if you can reach the exit, and "You shall not pass!" if it is not possible to reach the exit.

    Constraints:

    1 <= T <= 50

    1 <= N <= 50

    Sample Input:

    3

    ..

    ..D.

    D..D

    Sample Output:

    Possible

    You shall not pass!

    You shall not pass!

     1 #include<iostream>  
     2 #include<string.h>  
     3 #include<stdio.h>  
     4 #include<ctype.h>  
     5 #include<algorithm>  
     6 #include<stack>  
     7 #include<queue>  
     8 #include<set>  
     9 #include<math.h>  
    10 #include<vector>  
    11 #include<map>  
    12 #include<deque>  
    13 #include<list>  
    14 using namespace std;  
    15 int main()
    16 {
    17     char a[100];
    18     int n,flag=0;
    19     scanf("%d",&n);
    20     for(int i=0;i<n;i++)
    21     {
    22         flag=1;
    23         cin>>a;
    24         int m=strlen(a);
    25         for(int l=0;l<m;l++)
    26         {
    27             if(a[l]=='D')
    28             {
    29             flag=-1;
    30             printf("You shall not pass!
    ");
    31             break;
    32             }
    33         } 
    34         if(flag==1)
    35         printf("Possible
    ");
    36     }
    37     return 0;
    38 } 
    View Code
  • 相关阅读:
    linux下XAMP集成开发环境搭建流程总结
    一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10 http://www.jb51.net/css/383986.html
    安装软件时出现错误提示:无效类
    新建.xlxs文件打不开,旧的可以打开的解决办法
    PostgreSQL 自定义自动类型转换(CAST) 删除用 drop function integer_to_text(integer) CASCADE;
    php扩展不能加载的原因
    remote_addr(::1)不返回IPv4地址127.0.0.1的解决办法
    php转换字符串编码 iconv与mb_convert_encoding的区别
    PHPExcel获取CSV文件数据不准确,用以下方法获取
    日文SJIS编码字符串字符数获取方法
  • 原文地址:https://www.cnblogs.com/qscqesze/p/3856462.html
Copyright © 2011-2022 走看看