题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
#include<stdio.h> int main() { int arr[128] = { 0 }; char s[500] = { 0 }; gets(s); int sizes = 0; sizes = sizeof(s) / sizeof(char); int count=0; for (int i = 0; i < sizes; i++) { arr[s[i]-' ']++; } for (int i = 0; i < 128; i++) { if (arr[i] != 0) { count++; } } printf("%d", count); }
用哈希数组的方法来写。先输入字符串数组。然后创建一个数组。用来统计字符出现的次数。