题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
#include <stdio.h> #include <string.h> int main() { int arr[124] = {'\0'}; char buf[1001] = {'\0'}; scanf("%s", buf); int len = strlen(buf); for (int i = 0; i < len; i++) { arr[buf[i]]++; } int max = 0; int mark[124] = {0}; for (int j = 0; j < 124; j++) { for (int i = 0; i < 124; i++) { if (arr[i] > max) { max = arr[i]; mark[j] = i; } } max = 0; arr[mark[j]] = 0; } for (int i = 0; i < len; i++) { if(mark[i] == 0){ //之前没有这个if判断会出错,榜一给了提示 break; } printf("%c", (char)mark[i]); } return 0; }