loading ...
loading...

2007-08-10 | 串的算法设计

分享
标签:  

用定长顺序存储结构编写算法,求串S 所含不同字符的总数和每种字符的个数  

#include "stdio.h"

#include "string.h"

#define MAXSIZE 200

main()

{char str[MAXSIZE],a[MAXSIZE];

 int i,j,k,t=1;

 int b[MAXSIZE];

 clrscr();

 printf("Please enter a string:\n");

 scanf("%c",&str[t]);

 while(str[t]!='\n')

 {t++;

  scanf("%c",&str[t]);

 }

 str[0]=t;

 str[t++]=0;

 i=1;

 while(str[i]!=0)

 {a[i]=str[i];

  j=i+1;

  b[i]=1;

  while(str[j]!=0)

  {if(str[i]==str[j])

   {b[i]++;

    for(k=j;str[k]!=0;k++)

      str[k]=str[k+1];

   }

   else j++;

  }

  i++;

 }

 printf("The amount of different char is:%d\n",--i);

 i=1;

 while(a[i]!=0)

 {printf("char '%c':\t %d\n",a[i],b[i]);

  i++;

 }

}

分享 分享 |  评论 (0) |  阅读 (?)  |  固定链接 |  类别 (数据结构算法实现) |  发表于 14:55
搜狐博客温馨提示:搜狐博客官方不会要求参加活动的各位博友缴纳任何的手续费用。请勿轻信留言、评论中的中奖信息,更不要拨打陌生电话及向陌生帐户汇款,谨防受骗!识别更多网络骗术,请 点击查看详情
您还未登录,只能匿名发表评论。或者您可以 登录 后发表。
 
  *中国人爱国心,搜狗输入法爱国主题皮肤下载>>
表  情:
加载中...
回复通知: 同时用小纸条通知对方该回复