char *str = "AbcABca";
写出一个函数,查找出每个字符的个数,区分大小写,要求时间复杂度是n(提示用ASCII码)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 256
void calCharInString(char* str) {
if (str == NULL) {
return;
}
int hash[SIZE] = { 0 };
char* p = str;
while (*p != '\0') {
hash[*(p++)]++;
}
p = str;
int i = 0;
for (; i < SIZE; i++) {
if (hash[i]) {
printf("%3c:%3d", i, hash[i]);
}
}
}