点点滴滴”

导航

G 最水的一道

 

                                                                                                         G - 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!

 

题意:D表示障碍 .表示可以通过  障碍不可以通过  问是否可以走过路线

#include <iostream>
#include <string.h>
#include <stdio.h>

using namespace std;

int main()
{
    char a[55];
    int t;
    bool OK;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",&a);
        OK=false;
        int len=strlen(a);
        for(int i=0; i<len; i++)
        {
            if(a[i]=='D')
            {
                OK=true;
                break;
            }
        }
        if(OK)
            printf("You shall not pass!\n");
        else
            printf("Possible\n");
    }
    return 0;
}

 

posted on 2014-08-17 16:11  点点滴滴”  阅读(167)  评论(0编辑  收藏  举报