1 #include<stdio.h> 2 int main() 3 { 4 char *ppp= "aaassadddeeds"; 5 char c[255] = {0};//存放字符 6 uint32 ccnt[255] = { 0 };//存放字符对应的个数 7 char *t = NULL; 8 t = ppp; 9 uint32 index_i = 0; 10 uint32 count = 0;//总字符的个数 11 uint32 cnt = 0;//字符的种类数 12 while (*t != ‘\0‘) 13 { 14 /*在存储区域内之前出现过*/ 15 for (index_i = 0; index_i < cnt; index_i++) 16 { 17 if (c[index_i] == *t) 18 { 19 ccnt[index_i]++; 20 break; 21 } 22 } 23 /*在存储区域内第一次出现*/ 24 if (index_i >= cnt) 25 { 26 c[cnt++] = *t; 27 ccnt[index_i]++; 28 29 } 30 t++; 31 count++; 32 } 33 printf("%d\n", debug); 34 printf("%d\n", count); 35 for (index_i = 0; index_i < cnt; index_i++) 36 { 37 printf("%c %.2f%%\n", c[index_i], float((float)ccnt[index_i] / count)*100); 38 } 39 return 0; 40 }
C语言程序实现,统计字符串里面各个字符的个数在总字符个数中的比例,并打印输出。
原文:https://www.cnblogs.com/dongyanghaha/p/10753013.html