codeforces 1553B Reverse String
链接:
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相关推荐
- stone/reverse/string/digit(完美消除)
stone/reverse/string/digit(完美消除) stone: [问题描述] 平平去海边度假,海边有一片美丽的鹅卵石滩.平平在鹅卵石滩上捡了 $n$ 块美丽的 鹅卵石,并把它们排成一个 ...
- LeetCode之Reverse String II
1.题目 Given a string and an integer k, you need to reverse the first k characters for every 2k charac ...
- LeetCode344. Reverse String
344. Reverse String My Submissions QuestionEditorial Solution Total Accepted: 6975 Total Submissions ...
- 【跟Leon一起刷LeetCode】344. Reverse String
Reverse String Description: Write a function that takes a string as input and returns the string rev ...
- Reverse String
Write a function that takes a string as input and returns the string reversed. Example: Given s = &q ...
- 定间隔字符翻转(Reverse String II)
一.学习要点: 1.主要是对剩余字符长度的考虑,大于k的时候,对前k个进行翻转:小于k的时候,对实际个数进行全翻转:本程序中翻转个数用变量x来表示: 二.代码: #include<stdlib. ...
- CodeForces - 1535C Unstable String(思维)
题目链接:点击查看 题目大意:规定一个字符串将问号都替换成 000 或 111 后满足 010101 交替的话,该字符串是合法的,现在给出一个长度为 nnn 的字符串,求合法子串的个数 题目分析:两种 ...
- LeetCode之Reverse String
1.题目: Write a function that takes a string as input and returns the string reversed. Example: Given ...
- String | 344. Reverse String
题目:反转字符串 方法1: class Solution { public:string reverseString(string s) {int m = (s.size() -1) / 2;for( ...
- LeetCode 541. Reverse String II
题目: Given a string and an integer k, you need to reverse the first k characters for every 2k charact ...
最新文章
- 云计算还是python_云计算 与python
- power bi可视化表_如何使用Power BI可视化数据?
- B. Lynyrd Skynyrd(倍增 + 区间最小值)
- linux下toe网卡驱动,toe命令是干什么的,有没有大神解答一下
- mysql 触发器 二进制_Mysql 二进制日志格式 对存储过程,函数,触发器,事件的记录方式的影响...
- Atitit. 真正的全中国文字attilax易语言的特点以及范例
- swagger2-接口文档
- numpy矢量化运算
- 路由器、交换机配置命令简写对照表
- kron matlab_Matlab中repelem, repmat, kron重复数组
- CSS实现反方向圆角
- 前端开发毕业设计如何选题?怎么做?
- 还要帮彬彬做课件,我苦啊
- 华为云主机装oracle,hwcloud-通过华为云镜像服务创建ECS-镜像服务介绍与安装Redhat6.8...
- QT Opc ua Client (一) qopcua-- windows
- oracle代言人,好莱坞巨星布鲁斯南与欧琳正式签约成为代言人
- python launcher下载,python launcher是什么 python的launcher用法知识点总结
- 【深度学习】深度学习中的双线性变换?
- ubuntu18.10的桌面时钟
- 酒饮赛道“破圈”风暴加速席卷 汇泉国际IPO能否掀起“资本浪花”?