#include
#include
using namesapce std;
int main()
{
bool AcontainsB(char * A, char * B){
int have = 0;
while (*B){
have |= 1 << (*(B++) - 'A');
}
while (*A){
if ((have&(1 << *(A++) - 'A')) == 0){
return false;
}
}
return true;
}
char A[] = { "ABDCK" };
char B[] = {"ABC"};
bool res;
res = AcontainsB( A , B);
cout <<res << endl;
system("pause");
return 0;
}
C++不支持嵌套函数,试试这么写:
//注意添上include和using namespace
bool AcontainsB(char * A, char * B){
int have = 0;
while (*B){
have |= 1 << (*(B++) - 'A');
}
while (*A){
if ((have&(1 << *(A++) - 'A')) == 0){
return false;
}
}
return true;
}
int main()
{
char A[] = { "ABDCK" };
char B[] = {"ABC"};
bool res;
res = AcontainsB( A , B);
cout <<res << endl;
system("pause");
return 0;
}
谢谢!是这么回事儿,自定义函数不能放在主函数内。