题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
#include <stdio.h>
#include <string.h>
int main() {
char str[500], hash[127] = { NULL };
int i, b, cnt = 0, k;
scanf("%s", str);
for (i = 0; i < strlen(str); i++) {
k = str[i] % 17;
k = k + str[i] / 17;
while (hash[k] != NULL && hash[k] != str[i]) {
k++;
}//线性探测再散列
if (hash[k] != str[i]) {
hash[k] = str[i];
cnt++;
}
}
printf("%d", cnt);
return 0;
}