G-here be dragons
The Triwizard Tournament's third task is to negotiate a corridor of specified 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 '. 'If the segment is empty, or a' 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 <= 501 <= n <= 50 time limit: 1 smemory limit: 32 mbsample input: 3 .... d. D .. dsample output: possibleyou shall not pass! You shall not pass!
The Triwizard Tournament's third task is to negotiate a corridor of specified 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 indicates an obstacle. You can pass the obstacle.
#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;}