淡泊明志 宁静致远
分类: C/C++
2006-11-06 08:49:08
void StrSame(char * ch)
{
int TempCH[26];
int i,MaxLen =1,local,count=0;
for(i=0;i<26;i++)
TempCH[i] = 200;
while(*ch != '\0')
{
if(*ch == *(ch+1) || *ch == *(ch-1))
{
count++;
if(*ch != *(ch+1))
{
if( (TempCH[*ch-0x61] == 200) || count > TempCH[*ch-0x61])
TempCH[*ch-0x61] = count;
count = 0;
}
}
ch++;
}
for(i=0;i<25;i++)
{
if(TempCH[i] != 200 && TempCH[i+1] != 200)
{
if(TempCH[i]>TempCH[i+1])
{
if(MaxLen < TempCH[i])
{
MaxLen = TempCH[i];
local = i;
}
}
else
{
if(MaxLen < TempCH[i+1])
{
MaxLen = TempCH[i+1];
local = i+1;
}
}
}
}
printf("Character = %c\tNumber = %d\n",local+0x61,MaxLen);
}
main()
{
StrSame("abcdddaaaaabbbeefffda");
StrSame("aabcdddaaaaabbbeefffda");
StrSame("aaaaaabcdddaaaaabbbeefffda");
StrSame("aaabcdddaaaaabbbeefffdaaaaaa");
StrSame("aaabcdddaaaaabbbeefffdaaaaaab");
system("pause");
}