輸入格式:`char str1 [] = "helloworld";` 多組數據。輸出:變量名與不同字符個數(如 `str1 7`)。
#include <stdio.h>
#include <string.h>
int main() {
char line[200];
while (fgets(line, sizeof(line), stdin)) {
// 解析變量名與字符串內容
char var[50], str[100];
if (sscanf(line, "char %49s [] = \"%99[^\"]\";", var, str) != 2) continue;
int freq[256] = {0};
for (int i = 0; str[i]; i++) freq[(unsigned char)str[i]]++;
int distinct = 0;
for (int i = 0; i < 256; i++) if (freq[i]) distinct++;
printf("%s %d\n", var, distinct);
}
return 0;
}