View Code
#include " iostream "
using namespace std;
int main()
{
char ch[ 1000 ];
char a[ 1000 ][ 100 ];
int i,j;
int used[ 1000 ];
while (gets(ch))
{
if (strcmp(ch, " # " ) == 0 ) break ;
int L = strlen(ch);
int start = 0 ,end = L - 1 ;
for (i = 0 ;i < L;i ++ )
if (ch[i] != ' ' ) {start = i; break ;}
for (i = L - 1 ;i >= 0 ;i -- )
if (ch[i] != ' ' ) {end = i; break ;}
int s = 0 ,t = 0 ;
for (i = start ; i <= end; i ++ )
{
if (ch[i] != ' ' ) a[s][t ++ ] = ch[i];
if (ch[i] == ' ' && ch[i + 1 ] != ' ' )
{
a[s][t] = ' \0 ' ;
s ++ ;
t = 0 ;
}
}
a[s][t] = ' \0 ' ;
memset(used , 0 , sizeof (used));
int count = 0 ;
for (i = 0 ;i <= s;i ++ )
{
int mark = 0 ;
for (j = 0 ;j <= s;j ++ )
{
if (strcmp(a[i],a[j]) == 0 && used[j] == 0 ) {used[j] = 1 ; mark = 1 ;}
}
if (mark == 1 ) count ++ ;
}
cout << count << endl;
}
return 0 ;
}
转载于:https://my.oschina.net/garyun/blog/602920