变形课

在这里插入图片描述

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <sstream>
using namespace std;
//int h,l,n,bx,by,flag;
//int dir[8][2]={-1,-2,-2,-1,-2,1,-1,2,1,-2,2,-1,2,1,1,2};
//int dir[4][2]={0,1,-1,0,1,0,0,-1};
char a[1000][2],b='b',m='m',str[100];
int n,flag,cnt,sum,avg;
bool vis[1000];
void dfs(char ch)
{
    if(ch==m)
    {
        flag=1;
        return;
    }
    if(flag==1) return;
    for(int i=0;i<cnt;i++)
    {
        if(vis[i]==0&&a[i][0]==ch)
        {
            vis[i]=true;
            dfs(a[i][1]);
            vis[i]=false;
        }
    }
    return;
}
int main()
{
    cnt=0,flag=0;
    while(gets(str))
    {
        int len=strlen(str);
        if(str[0]=='0')//注意下输入
        {
            dfs(b);
            if(flag==1) cout<<"Yes."<<endl;
            else  cout<<"No."<<endl;
            memset(vis,0,sizeof(vis));
            memset(a,0,sizeof(a));
            cnt=0,flag=0;
            continue;
        }
        a[cnt][0]=str[0],a[cnt][1]=str[len-1];//存字符串头和尾
        cnt++;
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值