当前位置:网站首页>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] pytorch0.4.0 installation tutorial and GPU configuration collection (including test code)
- Rust writes near smart contract
- 2022年危险化学品经营单位安全管理人员特种作业证考试题库及模拟考试
- 17. how to understand multi version concurrency control and read / write sets of fabric smart contracts? (vernacular version)
- Advanced MySQL: how to learn MySQL source code
- 口碑好的食材配送信息化管理系统怎么样?
- [MySQL] online lock free delay free DDL artifact GH OST
- 生鲜配送分拣管理系统哪家比较强?
- STM32CubeMX的下载和安装方式
- mysql面试题
猜你喜欢
20 | pipeline oriented instruction design (Part 1): Modern CPU with multi-purpose
Dfinity (ICP) basic development tutorial-5
24 | adventure and prediction (III): thread pool in CPU
6. fabric2.2 stop clustering and delete data (use the official demo)
STM32CubeMX的下载和安装方式
MySQL table partitioning
第115页的gtk+编程例子——最简单的进度条2附带使用Anjuta写gtk程序的步骤
疫情之下的远程办公解决方案
赋予代码生命力--读代码整洁之道
汽配行业面临的难题用什么软件帮忙解决呢
随机推荐
【博弈论-完全信息静态博弈】 Nash均衡的应用
How to dynamically delete data rows in a table through JS (keep the head)
Rust writes near smart contract
SFTP login and download file script
How to install the bdtab (BD) new tab plug-in in edge browser (Graphic tutorial)
【深度学习】:《PyTorch入门到项目实战》(十二)卷积神经网络:填充(padding)和步幅(stride)
Dfinity (ICP) basic development tutorial-5
19 | establish data path (bottom): instruction + operation =cpu
Web site access excel in IIS
获取类的属性
Success logarithm of leetcode spells and potions
24 | adventure and prediction (III): thread pool in CPU
udf_ interval_ to_ Hourno() function
Structural analysis of hyperledger fabric (I)
Did decentralized digital identity
The uniapp applet dynamically generates tabbar based on permissions
Dfinity (ICP) identity authentication and ledger quick start-3
How to hide tabs in nailing applet
Basic operation of dfinity (ICP) development-4
口碑好的食材配送信息化管理系统怎么样?