zoukankan      html  css  js  c++  java
  • C语言程序实现,统计字符串里面各个字符的个数在总字符个数中的比例,并打印输出。

     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 != '')
    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
    ", debug);
    34     printf("%d
    ", count);
    35     for (index_i = 0; index_i < cnt; index_i++)
    36     {
    37         printf("%c %.2f%%
    ", c[index_i], float((float)ccnt[index_i] / count)*100);
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    Spring(一)Spring的基本应用
    flask摘记
    python摘记
    String Algorithm
    leetcode -- hard part
    leetcode -- medium part
    leetcodo--Easy part
    unix网络编程
    SQL
    计算机网络知识
  • 原文地址:https://www.cnblogs.com/dongyanghaha/p/10753013.html
Copyright © 2011-2022 走看看