当前位置:网站首页>Determine whether a string is rotated from another string
Determine whether a string is rotated from another string
2022-06-13 08:10:00 【Stupid little bird learning code】
// Method 1
int is_left_move(char* s1,char* s2)
{
int len = strlen(s1);
int i = 0;
for(i=0;i<len;i++)
{
left_move(s1,1);// There are several reasons why the following rotation is not possible It changes after the rotation
// The next rotation is not the result of the original string rotation
int ret = strcmp(s1,s2);// Same back 0 Different back 1
if(ret == 0)
{
return 1;
}
// You can't just else After all the judgments have been made
}
return 0;
}
// Method 2
//abcdefabcdef All the inversion results in a subset of this string
int is_left_move_2(char* str1,char* str2)
{
int len1 = strlen(str1);
int len2 = strlen(str2);
if(len1 != len2)
{
return 0;
}
//1. stay str1 Append a... To the string str1 character string
//strcat This library function You can't add to yourself Will be able to \0 Get rid of
//strncat
strncat(str1,str1,len1);
//2. Judge str2 Whether the string pointed to is str Substring of the string pointed to
//strstr- Find Zichuan
char* ret = strstr(str1,str2);// stay str1 In looking for str2 Return null pointer not found
if(ret == NULL)
{
return 0;
}
else
{
return 1;
}
return 0;
}
// The main function
int main()
{
char arr1[] = "abcdef";//char arr1 = "abcdef" This will cause an error The reason is that by this definition
char arr2[] = "cdefa";// Is a defined constant string No modification allowed So it is still defined as an array
//int ret = is_left_move(arr1,arr2);
int ret = is_left_move_2(arr1,arr2);
if(ret == 1)
{
printf("YES\n");
}
if(ret == 0)
{
printf("NO\n");
}
return 0;
}
边栏推荐
- 【PYTORCH】RuntimeError: torch. cuda. FloatTensor is not enabled.
- Dfinity (ICP) basic development tutorial-5
- 分布式系统之道:Lamport 逻辑时钟
- [MySQL] rapid data deletion recovery tool - binlog2sql
- Web site access excel in IIS
- ERP basic data Huaxia
- 【完全信息静态博弈-Nash均衡的特性】
- Shell脚本常用开发规范
- Give code vitality -- the way to read code neatly
- 2022 simulated examination question bank and online simulated examination of hoisting machinery command examination questions
猜你喜欢
1. fabric2.2 comprehensive learning - Preface
ERP基础数据 金蝶
【PYTORCH】Expected object of type torch. xxxTensor but found type torch. cuda. xxxTensor(torch0.4.0)
2022年电工(初级)考题及模拟考试
Local shooting range 2- file upload vulnerability (III) - Network Security
25 | adventure and prediction (IV): it's raining today. Will it rain tomorrow?
2022 simulated examination question bank and online simulated examination of hoisting machinery command examination questions
v-for生成的子组件列表删除第n行出现数据错乱问题
【博弈论-完全信息静态博弈】 Nash均衡
2022年G3锅炉水处理操作证考试题库模拟考试平台操作
随机推荐
Edge browser uses bdtab new tab plug-in (BD new tab)
Remote office solution under epidemic situation
set实现名单查找与排除
[redis problem] record a big key problem handling
【clickhouse专栏】基础数据类型说明
uniapp 小程序根据权限动态生成 tabbar
How to install the bdtab (BD) new tab plug-in in edge browser (Graphic tutorial)
力扣(LeetCode)163. 缺失的区间(2022.06.12)
Dfinity (ICP) identity authentication and ledger quick start-3
[MySQL] rapid data deletion recovery tool - binlog2sql
2022 simulated examination question bank and online simulated examination of hoisting machinery command examination questions
leetcode 咒语和药水的成功对数
Install cuda+cusp environment and create the first helloword starter project
25 | adventure and prediction (IV): it's raining today. Will it rain tomorrow?
1. fabric2.2 comprehensive learning - Preface
Data disorder occurs when the n-th row of the subcomponent list generated by V-for is deleted
Create a substrate private network
23 | adventure and prediction (II): relay race in the assembly line
[game theory complete information static game] Application of Nash equilibrium
Recognition of COVID-19 based on paddlepaddle