题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
#include <stdio.h> #include <string.h> int main() { char arr[502] = {-1}; memset(arr, -1, 502); //去除末尾的 "\r\n" fgets(arr, 502, stdin); arr[strcspn(arr,"\n")] = -1; arr[strcspn(arr,"\r")] = -1; //scanf("%s", arr); char flag[128] = {0}; int i =0; for (i = 0; ; i++) { //判断是否到达了末尾 if (arr[i] == -1) { break; } flag[arr[i]] = 1; //printf("i:%d\n", i); } int ret = 0; for (i = 0; i < 128; i++) { if (flag[i] == 1) { ret++; } } printf("%d", ret); return 0; }