十年網站開發(fā)經驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網站問題一站解決
這是統(tǒng)計字符串的不同字符的個數啊。
從事溫江服務器租用,服務器租用,云主機,虛擬空間,域名申請,CDN,網絡代維等服務。
#includestdio.h
int main()
{char s[200];
int i,a[96]={0},n;
gets(s);
for(i=0;s[i];i++)
a[s[i]-32]=1;
for(n=i=0;i96;i++)
n+=a[i];
printf("%d\n",n);
return 0;
}
c:
#include?stdio.h
#include?stdlib.h
#include?math.h
#include?string.h
int?countsub(char?*str,?char?*ss)?{
int?len?=?strlen(str),?index?=?0,?max?=?0;
int?*maxStr?=?(int*)malloc(sizeof(int)?*?len);
for?(index?=?0;?index??len;?++index)?{
maxStr[index]?=?0;
}
index?=?0;
for?(int?i?=?0;?str[i]?!=?'\0';?++i)?{
int?j?=?0;
for?(;?ss[j]?!=?'\0'??str[i?+?j]?!=?'\0'??ss[j]?==?str[i?+?j];?++j);
if?(j??0??ss[j]?==?'\0')?{
maxStr[index]++;
i?+=?j?-?1;
}?else?{
index++;
}
if?(maxStr[index]??max)
max?=?maxStr[index];
}
return?max;
}
int?main()?{
char?s1[1000]?=?{?0?},?s2[100]?=?{?0?};
gets(s1);
gets(s2);
printf("%d\n",?countsub(s1,?s2));
return?0;
}
一般有三種辦法可以計算英文字符的個數:
1)使用strlen()函數
2)從首字符開始,邊掃描邊計數,到'\0'為止('\0'不計數)
3)從首字符開始,掃描到'\0'為止,'\0'地址與字符串首地址的差。
使用系統(tǒng)標準庫函數strlen(s)就可以測得字符數組s中的字符串的字符個數,也就是字符串的長度,需要包含string.h頭文件。