题解 | #HJ10 字符个数统计#
字符个数统计
http://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
思路:创建128大小的数组,标记出现过的字符,然后统计标记个数
#include <stdio.h>
#include <stdbool.h>
int main() {
bool flags[128] = {false};
char string[500];
scanf("%s", string);
int length = strlen(string);
for (int i = 0; i < length; i++) {
if (0 <= string[i] && string[i] <= 127) {
flags[string[i]] = true;
}
}
int count = 0;
for (int i = 0; i < 128; i++) {
if (flags[i] == true) {
count++;
}
}
printf("%d\n", count);
return 0;
}