题目:
字符串里里面字符出现的次数和出现哪些不同的字符
such as 字符串“aaaabbbccd” 打印出出现a4次,b3次,c2次,d1次,出现的不同字符的字符串为“abcd”,或者按照规则打印字符串“4a3b2c1d”
代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>void getJustOnce(char* inputArray, char* outputArray, int length) {bool result[26] = {0};int i, j;for (i = 0, j = 0; i < length; i++) {if (result[inputArray[i] - 'a'] == false) {result[inputArray[i] - 'a'] = true;outputArray[j++] = inputArray[i];}}outputArray[j] = '\0'; //记得一定要加上
}void printCharCount1(char* inputArray, int length) {int result[26] = {0};int i, j;for (i = 0; i < length; ++i) {++result[inputArray[i] - 'a'];}for (j = 0; j < 26; ++j) {if (result[j] != 0) {