csdn在线编程里面的一个排列组合题

是csdn在线编程里面的一个问题


回文字符串是指从左到右和从右到左相同的字符串,现给定一个仅由小写字母组成的字符串,
你可以把它的字母重新排列,以形成不同的回文字符串。
输入:非空仅由小写字母组成的字符串,长度不超过100;
输出:能组成的所有回文串的个数(因为结果可能非常大,输出对1000000007取余数的结果)。
例如:输入"aabb" 输出为2(因为“aabb”对应的所有回文字符串有2个:abba和baab)
函数头部 c: int palindrome(const char *s); c++ int palindrome(const string &s); java public static int palindrome(String s)

我写了代码出来,自认为应该是对的了,不知道为啥提交上去,测试用例没有通过,而那个在线编程最讨厌的是,不会告诉你具体哪个用例失败了,求高人指点一下,我下面的代码会在哪个用例上失败,感激不尽!

int palindrome(const string &s)
{
    const unsigned int zhishu = 1000000007;
    int len = s.length();
    if(len > 100) return -1;
    int chararr[26];
    for(int i=0; i<26; ++i){
        chararr[i] = 0;
    }
    int temp;
    for(int i=0; i<len; ++i){
        temp = s[i] - 'a';
        if(temp < 0 || temp >= 26) return -1;
        ++chararr[temp];
    }
    int sum = 0;
    int jishu = 0;
    for(int i=0; i<26; ++i){
        if(chararr[i]%2 != 0){
            ++jishu;
        }
        sum += chararr[i]/2;
    }
    if(jishu > 1) return -1;
    unsigned int result = 1;
    int chushu = 1;
    int j = 0;
    int i = sum;
    while(i > 1){
        if(chushu < 2 && j < 26){
            chushu = chararr[j]/2;
            ++j;
        }
        while(chushu > 1 && result % chushu == 0){
            result /= chushu;
            --chushu;
        }
        result *= i;
        result %= zhishu;
        --i;
    }
    while(chushu > 1 || j < 26){
        if(chushu < 2){
            chushu = chararr[j]/2;
            ++j;
        }
        if(chushu < 2){
            continue;
        }
        result /= chushu;
        --chushu;
    }
    return result;
}
原文地址:https://www.cnblogs.com/studynote/p/3463140.html