编程艺术之1.2字符串包含_test1

来源:互联网 发布:sdk2000数据无效 编辑:程序博客网 时间:2024/05/22 12:53
/*变位词如果两个字符串的字符一样,但是顺序不一样,被认为是兄弟字符串,比如 bad 和 adb即为兄弟字符串,现提供一个字符串,如何在字典中迅速找到它的兄弟字符串,请描述数据结构和查询过程。*/#include<stdio.h>#include<string.h>int main(void){char c1[] = "abc";char c2[] = "abe";int tmp[10] = {0}, i, j;int count = 0;for (i = 0; i < strlen(c1); i++){++tmp[c1[i] - 'a'];}for (j = 0; j < strlen(c2); j++){--tmp[c2[j] - 'a'];if (tmp[c2[j] - 'a']!=0){printf("the string c1 & c2 is not brother\n");break;}}if (j == strlen(c2)){printf("the string c1 & c2 is brother\n");}return 0;}

0 0
原创粉丝点击