菜鸟向前冲hxw 2016-03-11 13:32 采纳率: 100%
浏览 3089
已采纳

本地函数定义非法;C++

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

}

  • 写回答

2条回答 默认 最新

  • cxsmarkchan 2016-03-11 13:37
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?