解题思路:对于c来说hash函数求出各个符号的数量,不为0时就输出即可,python利用字符串count函数就可以了。
c语言代码如下:
#include<stdio.h>
int output_c(char c,int *count)
{if(*count!=0){putchar(c);(*count)--;}return 1;
}
int main()
{char a[10001];int a_count[128]={0};int i;scanf("%s",a); for(i=0;a[i]!='\0';i++){a_count[a[i]]++;}int count_P=a_count['P'],count_A=a_count['A'],count_T=a_count['T'];int count_e=a_count['e'],count_s=a_count['s'],count_t=a_count['t'];int count=count_P+count_A+count_T+count_e+count_s+count_t;for(i=0;i<count;i++){output_c('P',&count_P);output_c('A',&count_A);output_c('T',&count_T);output_c('e',&count_e);output_c('s',&count_s);output_c('t',&count_t);}printf("\n");return 0;
}
python代码:
s=input()
out='PATest'
count=0
count_out=[0]*6
for i in out:index=out.index(i)count_out[index]=s.count(i)count+=count_out[index]
for i in range(count):for i in out:index=out.index(i)if count_out[index]>0:count_out[index]-=1print(i,end='')
print()