//#include "stdafx.h"//vc++6.0加上这一行.
#include "ctype.h"
#include
#include
using namespace std;
int mycmp(const void *a,const void *b){
return *(char *)a-*(char *)b;
}
bool isAlphaNumeric(char& c){
return c>='1' && c<='9' || c>='a' && c<='z' || c>='A' && c<='Z';
}
bool isAnagram(string str1, string str2){
char s1[51],s2[51];
int ln=str1.length();
if(ln!=(int)str2.length())
return false;
for(int i=0,j=0,k=0;i
if(s1[j]>='A' && s1[i]<='Z')
s1[j]|=0x20;
j++;
}
if(isAlphaNumeric(s2[k]=str2.c_str()[i])){
if(s2[k]>='A' && s2[k]<='Z')
s2[k]|=0x20;
k++;
}
}
s1[j]=s2[k]='\0';
if((ln=strlen(s1))!=(int)strlen(s2))
return false;
qsort(s1,ln,sizeof(char),mycmp);
qsort(s2,ln,sizeof(char),mycmp);
return (bool)!strcmp(s1,s2);
}
void main(void){
string str1,str2;
cout << "Please enter the first string:";
getline(cin,str1);
cout << "Please enter the second string:";
getline(cin,str2);
cout << "The two strings are anagrams: " << isAnagram(str1,str2) << endl;
}
把工程保存发到我邮箱帮你