题解 | #字符个数统计#
字符个数统计
http://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
通过哈希表记录字母是否出现,出现则置位, 没有出现则统计数据+1
#include <stdio.h> #include <string.h> int main() { int i; char hash[128] = {0}; // 哈希表标识字符是否出现 char buf[500] = {0}; int ret = 0; gets(buf); for (i = 0; i < strlen(buf); i++) { if (hash[buf[i] - ' '] == 0) { hash[buf[i] - ' '] = 1; ++ret; } } printf("%d", ret); return 0; }