G - Cutie Pie Gym - 101020G

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

直接暴力就可以,个人觉得字符数组输入的时候比较难。

#include<bits/stdc++.h>


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<map>

using namespace std;

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值