|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <stdio.h>
- #include <string.h>
- #define NUM 128
- int main()
- {
- int ch, i, j = 0, max = 0;
- int input_num = 0;
- int ascii[NUM] = { 0 };
- char count[NUM] = "";
- printf("请输入英文文本:");
- while ((ch = getchar()) != '\n')
- {
- ascii[ch]++; // 字符对应的ASCII码加1
- input_num++;
- }
- for (i = 0; i < NUM; i++)
- {
- if (ascii[i])
- {
- count[j++] = i;
- if (ascii[i] > ascii[max])
- {
- max = i;
- }
- }
- }
- printf("你总共输入了%d个字符,其中不同的字符个数有%d个。\n", input_num, strlen(count));
- printf("它们是:%s\n", count);
- printf("出现次数最多的字符是\'%c\',它总共出现了%d次。\n", max, ascii[max]);
- return 0;
- }
复制代码
其中ascii[ch]++这里我想了一晚上实在搞不懂。
这里输入字符对应的ASCII码+1我是理解,可是每输入一个相同字符就+1这里我无法理解是怎么实现的。
求讲解具体……
其实字符就是一个数字
大写字母C,就是数字67
- #include <stdio.h>
- int main(void)
- {
- char c = 'C';
- printf("%c\n", c);
- printf("%d\n", c);
- return 0;
- }
复制代码
|
|