資源簡介
字符串統(tǒng)計函數(shù),統(tǒng)計不同字符個數(shù)和每個字符出現(xiàn)的次數(shù)。用一個簡單的數(shù)據(jù)結(jié)構(gòu)做的,注釋很清楚。
代碼片段和文件信息
//?CharStatistics.cpp?:?Defines?the?entry?point?for?the?console?application.
//
/*
Date2009.6.25
By?:summon
Vervion:?v1.0
Fun:?統(tǒng)計一個字符串中不同字符的個數(shù)和每種字符出現(xiàn)的次數(shù)
Time?complexity:?O(n*m)n表示字符個數(shù),m表示不相同的字符的個數(shù)
Space?complexity:?O(2*n?+1)n表示字符的個數(shù)
*/
#include?“stdafx.h“
#include?
#include?
#include?
#define?MAX_LEN?100//能夠記錄的最大的不相同的字符個數(shù)
typedef?struct?
{
int?ch[MAX_LEN];//存儲各不相同的字符
int?count[MAX_LEN];//對應(yīng)記錄各個不同字符出現(xiàn)的次數(shù)
int?pos;//最后不為‘\0‘的元素位置
}storage;
void?CharStat(const?char?*pchDest?storage?&stor);
int?main(int?argc?char*?argv[])
{
char?pInput[MAX_LEN]?=?{0};
printf(“Input?a?string!\n“);
gets(pInput);
storage?stor;//inint
stor.pos?=?-1;//記錄位置的初始值為-1
????for?(int?i=0;?i {
stor.ch[i]?=?0;
stor.count[
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2100??2009-06-25?19:35??CharStatistics.cpp
-----------?---------??----------?-----??----
?????????????????2100????????????????????1
評論
共有 條評論