解题思路:
1、首先遍历字符串 将字母放在 map 对应[0 --25 ] 数字放在map [26 -- 35];
2、排序 (排序条件 特别注意如果 两个字母出现次数相同,则acill 码小的放在前面) 排序后的用out 数组来保存;
3、输出(但是需要判断如果该字符数 为0 ,则跳过该字符);
#include <stdio.h>
#include <ctype.h>int main(void) {
char str[1001] = {0};
while (fgets(str, 1001, stdin)) {
int map[36] = {0};
char out[36] = {0};
int length = strlen(str) -1;
for (int i = 0; i < length; i++) {
if (islower(str[i]) != 0) {
int flag = str[i] - 'a';
map[flag]++;
out[flag] = str[i];
} else {
int flag = str[i] - '0';
map[flag+26]++;
out[flag+26] = str[i];
}
}
for (int i = 0; i < 36; i++) {
for (int j = i+1; j < 36; j++) {
int temp = 0;
char temp_c = 0;
int flag = out[i] - out[j];
if ((map[i] < map[j]) || ((map[i] == map[j]) && (flag > 0))){
temp = map[i];
temp_c = out[i];
map[i] = map[j];
out[i] = out[j];
map[j] = temp;
out[j] = temp_c;
}
}
}
for (int i = 0; i < 36; i++) {
if (map[i] != 0) printf("%c", out[i]);
}
printf("\n");
}
return 0;
}