Cutie Pie

Consider a NxM small-letters grid. SVU asked you to check whether this grid is a Cutie Pie or not A grid is a cutie pie if you can find the word "pie" in any direction (vertical, horizontal, and radial). Your program should output "Cutie Pie!" if the grid contains the word "pie" or "Sorry Man" otherwise

Input

The first line contains T 1<=T<=10000 the number of test cases. The followed T lines represent the test cases, each one contains two integers 0 < N,M  ≤  20 then N lines each of them contains M English small-letter separated by space characters. There is a blank line between each two successive test cases.

Output

For each test case output "Cutie Pie!" if the grid in the test case contains the word "pie" or "Sorry Man" otherwise.

Examples

Input

2
3 5
o p r d t
i i i i e
f f s e d

4 3
o p r
o k r
i i u
f f s

Output

Cutie Pie!
Sorry Man

AC代码(直接暴力就可以注意题意一开始以为是说这些字母中出现pie就可以后来发现需要连在一起的pie还有输入的时候注意一下)

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n, m, i, j;
        char a[30][30];
        scanf("%d%d",&n,&m);
        for(i = 0;i<n;i++)
        {
            for(j = 0;j<m;j++)
            {
                scanf(" %c",&a[i][j]);
            }
        }
        int flag = 0;
        for(i = 0;i<n;i++)
        {
            for(j = 0;j<m;j++)
            {
                if(a[i][j]=='p')
                {
                    if((a[i-1][j]=='i'&&a[i-2][j]=='e')||(a[i+1][j]=='i'&&a[i+2][j]=='e')||(a[i][j+1]=='i'&&a[i][j+2]=='e')||(a[i][j-1]=='i'&&a[i][j-2]=='e')
                    ||(a[i+1][j+1]=='i'&&a[i+2][j+2]=='e')||(a[i-1][j-1]=='i'&&a[i-2][j-2]=='e')||(a[i-1][j+1]=='i'&&a[i-2][j+2]=='e')||(a[i+1][j-1]=='i'&&a[i+2][j-2]=='e'))
                    {
                        flag = 1;
                        break;
                    }
                }
            }
        }
        if(flag==1)
            printf("Cutie Pie!\n");
        else
            printf("Sorry Man\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41524782/article/details/81358161
pie
今日推荐