solution.cpp 510 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <stdio.h>
#include <string.h>
int main() //计数排序
{
	char s[1000];
	scanf("%s", &s);
	int len = strlen(s);   //获取字符串s的长度
	int helper[256] = {0}; //ascll范围在0~255之间(包括0和255)
	int max = 0, min = len;
	for (int i = 0; i < len; i++)
	{
		helper[s[i]]++; //计数
	}
	for (int i = 0; i < 256; i++)
	{
		if (helper[i] > max)
		{
			max = helper[i];
		}
		if (helper[i] < min && helper[i] != 0)
		{
			min = helper[i];
		}
	}
	printf("%d\n", max - min);
	return 0;
}