标签:返回 col pre clu span ++ strlen amp ring
例如:给定s1 = AABCD和s2 = BCDAA,返回1,给定s1 = abcd和s2 = ACBD,返回0.
AABCD左旋一个字符得到ABCDA
AABCD左旋两个字符得到BCDAA
AABCD右旋一个字符得到DAABC
1 #include<stdio.h>
2 #include<string.h>
3
4 void Left_rotate(char* start, char* end)
5 {
6 //ABCD
7 //BACD
8 while (*end != ‘\0‘)
9 {
10 *start = *start^*end;
11 *end = *start^*end;
12 *start = *start^*end;
13 ++start;
14 ++end;
15 }
16 }
17
18 int Find_str(char* str,char* str1)
19 {
20 int k = strlen(str);
21 while (k--)
22 {
23 if (strcmp(str, str1) == 0)
24 {
25 return 1;
26 }
27 else
28 {
29 Left_rotate(str, str + 1);
30 }
31 }
32 return 0;
33 }
34
35 int main()
36 {
37 char str[100];
38 char str1[100];
39 printf("请输入一段字符串:\n");
40 scanf("%s", &str);
41 printf("请输入要判断的字符串:\n");
42 scanf("%s",&str1);
43 int find = Find_str(str, str1);
44 printf("%d",Find_str(str,str1));
45
46 return 0;
47 }
标签:返回 col pre clu span ++ strlen amp ring
原文地址:https://www.cnblogs.com/cuckoo-/p/10387601.html