链接:

https://codeforces.com/problemset/problem/1553/B

题意:

给一个字符串s,从第x个字符开始先向右读a个字符,再向左读b个字符,判断是否可以组成字符t。

本题可以直接用dfs遍历所有的情况,如果出现可以组成字符t的情况,就返回true。

代码如下:

#include<iostream>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
string s, t;
bool f;
void dfs(int position, string res, bool dir) {//true向右if(f || res.size() > s.size()){return;}if (dir) {for (int i = position; i < s.size(); i++) {res += s[i];if (res == t) {f = true;break;}dfs(i - 1, res, false);}}else {for (int i = position; i >= 0; i--) {res += s[i];if (res == t) {f = true;break;}}}
}
int main() {int T;cin >> T;while (T--) {cin >> s >> t;f = false;for (int i = 0; i < s.size(); i++) {dfs(i, "", true);if (f) {break;}}if (f) {cout << "YES";}else {cout << "NO";}cout << endl;}
}

codeforces 1553B Reverse String相关推荐

  1. stone/reverse/string/digit(完美消除)

    stone/reverse/string/digit(完美消除) stone: [问题描述] 平平去海边度假,海边有一片美丽的鹅卵石滩.平平在鹅卵石滩上捡了 $n$ 块美丽的 鹅卵石,并把它们排成一个 ...

  2. LeetCode之Reverse String II

    1.题目 Given a string and an integer k, you need to reverse the first k characters for every 2k charac ...

  3. LeetCode344. Reverse String

    344. Reverse String My Submissions QuestionEditorial Solution Total Accepted: 6975 Total Submissions ...

  4. 【跟Leon一起刷LeetCode】344. Reverse String

    Reverse String Description: Write a function that takes a string as input and returns the string rev ...

  5. Reverse String

    Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...

  6. 定间隔字符翻转(Reverse String II)

    一.学习要点: 1.主要是对剩余字符长度的考虑,大于k的时候,对前k个进行翻转:小于k的时候,对实际个数进行全翻转:本程序中翻转个数用变量x来表示: 二.代码: #include<stdlib. ...

  7. CodeForces - 1535C Unstable String(思维)

    题目链接:点击查看 题目大意:规定一个字符串将问号都替换成 000 或 111 后满足 010101 交替的话,该字符串是合法的,现在给出一个长度为 nnn 的字符串,求合法子串的个数 题目分析:两种 ...

  8. LeetCode之Reverse String

    1.题目: Write a function that takes a string as input and returns the string reversed. Example: Given ...

  9. String | 344. Reverse String

    题目:反转字符串 方法1: class Solution { public:string reverseString(string s) {int m = (s.size() -1) / 2;for( ...

  10. LeetCode 541. Reverse String II

    题目: Given a string and an integer k, you need to reverse the first k characters for every 2k charact ...

最新文章

  1. 云计算还是python_云计算 与python
  2. power bi可视化表_如何使用Power BI可视化数据?
  3. B. Lynyrd Skynyrd(倍增 + 区间最小值)
  4. linux下toe网卡驱动,toe命令是干什么的,有没有大神解答一下
  5. mysql 触发器 二进制_Mysql 二进制日志格式 对存储过程,函数,触发器,事件的记录方式的影响...
  6. Atitit. 真正的全中国文字attilax易语言的特点以及范例
  7. swagger2-接口文档
  8. numpy矢量化运算
  9. 路由器、交换机配置命令简写对照表
  10. kron matlab_Matlab中repelem, repmat, kron重复数组
  11. CSS实现反方向圆角
  12. 前端开发毕业设计如何选题?怎么做?
  13. 还要帮彬彬做课件,我苦啊
  14. 华为云主机装oracle,hwcloud-通过华为云镜像服务创建ECS-镜像服务介绍与安装Redhat6.8...
  15. QT Opc ua Client (一) qopcua-- windows
  16. oracle代言人,好莱坞巨星布鲁斯南与欧琳正式签约成为代言人
  17. python launcher下载,python launcher是什么 python的launcher用法知识点总结
  18. 【深度学习】深度学习中的双线性变换?
  19. ubuntu18.10的桌面时钟
  20. 酒饮赛道“破圈”风暴加速席卷 汇泉国际IPO能否掀起“资本浪花”?

热门文章

  1. 一文让你理解什么是shallow heap及retained heap
  2. 工欲善其事,必先利其器——学会不将就,让自己事半功倍!
  3. N个鸡蛋放到M个篮子中
  4. 微信小游戏声明文件(d.ts)
  5. CSAPP第四章家庭作业参考答案
  6. Windows10的右键菜单添加“管理员取得所有权”
  7. 塞拉菲娜创始人 - 木子
  8. coredump 瘦身风云
  9. 安卓工具类集合—— 1 时间、时间戳转换工具
  10. harmonyos在哪里使用,HarmonyOS 2.0 手机版使用初体验 ——手机开发者 (Beta版)