题目描述:
Compile a function. The function is used to calculate the number of different characters in a character string. Characters must be in ACSII range (from 0 to 127). You do not need to calculate characters that are not in the range.
- Example 1:
Input: abcd
Output: 4
- Example 2:
Input: abcdee
Output: 5
#include <stdlib.h>
#include <string.h>
#include "oj.h"
/*
功能:
输入:字符串
输出:无
返回:字符个数
*/
//桶排序
int GetCount( char* strInValue )
{
int len = strlen(strInValue);
int count = 0;
int strCount[128] = {0};
for(int i = 0;i < len-1;i++)
{
if(strInValue[i] >= 0 && strInValue[i] <= 127)
{
strCount[strInValue[i]]++;
}
}
for(int i = 0;i < 128;i++)
{
if(strCount[i] >= 1)
{
count++;
}
}
return count ;
}