#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;
}