欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[Pointers and C-String]D. Liang 7.18 Anagrams

程序员文章站 2024-03-01 16:57:22
...

好久没更新了,因为懒otz
Description
Write a function that checks whether two words are anagrams. Two words are anagrams if they contain the same letters in any order. For example, “silent” and “listen” are anagrams. The header of the function is as follows:

int isAnagram(const char * const s1, const char * const s2)

int isAnagram(const char * const s1, const char * const s2){
	int re=0;
	int size=strlen(s1);
	int num=strlen(s2);
	if(num!=size)return 0;
	char count[size];
	for(int i=0;i<size;i++)count[i]=*(s2+i);
	for(int i=0;i<size;i++){
		for(int k=0;k<size;k++){
			if(*(s1+k)==count[i]){
				re++;
				count[i]=0;//意思是比较过的就不要再比了
			}
		}
	}
	if(re==size)return 1;
	else return 0;
}