[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));
}