您的位置:首页 > 产品设计 > UI/UE

Find char sequence consists of same chars but in different order

2013-08-10 22:13 148 查看
Using two maps one processes ++ and the other processes -- operation;

#include <stdlib.h>

char a[] = {'a','b','c','d','e'};
char b[] = {'a','b','d','d','e'};
int map[128];

void compare(char* a,char* b, int len){
int i;
for(i = 0; i < len; i++){
map[a[i]]++;
}
for(i = 0; i < len; i++){
map[b[i]]--;
}
}

int isEqual(){
int i = 0;
for(; i < 256; i++){
if(map[i] != 0){
return -1;
}
}
return 1;
}

int main(){
compare(a, b, 5);
int result = isEqual();
printf("%d", result);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐