#include <stdio.h>
#include <string.h>
void main()
{
char word[100][100];
char s[100];
char *p;
char *q;
int count = 0,cnt=0,k=0;
int i=0,j=0;
gets(s);
p=q=s;
while(p = strchr(p,' '))
{
count++; //判断有几个单词
strncpy(word[i],q,p-q);
word[i][p-q] = '\0';
p = p+1;
q = p;
i++;
}
if(p == NULL)
{
strncpy(word[i],q,strlen(q));
word[i][strlen(q)]='\0';
}
cnt=count;
for(i=0;i<=cnt;i++)
{
for(j=i+1;j<=cnt;j++)
if(strcmp(word[i],word[j])==0){strcpy(word[j],"");}
if(strcmp(word[i],"")!=0) //判断如果没有有标记
k++; //不同单词+1
}
printf("%d\n",k);
}
蓝桥杯 不同单词个数统计
最新推荐文章于 2023-07-05 10:47:14 发布