[Cpp]
# Include <stdlib. h>
Int perfect (const char * s)
{
Char * p = s;
Int count_array [26] = {0 };
Int count = 26;
Int idle = 0;
# Include <stdlib. h>
Int perfect (const char * s)
{
Char * p = s;
Int count_array [26] = {0 };
Int count = 26;
Int idle = 0;
[Cpp]
Int I = 0;
To_upper (p );
While (* p)
Count_array [* p ++-'a'] ++;
Sort (& count_array );
For (I = 0; I <sizeof (count_array)/sizeof (int); I ++)
Idle + = count_array [I] * count --;
Return idle;
}
Void sort (int * array)
{
Int I = 0;
Int tmp = 0;
Int j = 0;
For (I = 0; I <26; I ++)
{
For (j = I; j <26; j ++)
{
If (array [j]> array [I])
{
Tmp = array [j];
Array [j] = array [I];
Array [I] = tmp;
}
}
}
}
Void to_upper (char * s)
{
While (* s)
{
If (* s> 96 & * s <= 123)
* S = * s-32;
* S ++;
}
}
Int main ()
{
Char s [20] = "DAD ";
Printf ("pec is % d! \ N ", perfect (s ));
}
Int I = 0;
To_upper (p );
While (* p)
Count_array [* p ++-'a'] ++;
Sort (& count_array );
For (I = 0; I <sizeof (count_array)/sizeof (int); I ++)
Idle + = count_array [I] * count --;
Return idle;
}
Void sort (int * array)
{
Int I = 0;
Int tmp = 0;
Int j = 0;
For (I = 0; I <26; I ++)
{
For (j = I; j <26; j ++)
{
If (array [j]> array [I])
{
Tmp = array [j];
Array [j] = array [I];
Array [I] = tmp;
}
}
}
}
Void to_upper (char * s)
{
While (* s)
{
If (* s> 96 & * s <= 123)
* S = * s-32;
* S ++;
}
}
Int main ()
{
Char s [20] = "DAD ";
Printf ("pec is % d! \ N ", perfect (s ));
}