bool ContainsDuplicates( apstring str )
{
int i, j;
for( i = 0; i < str.length( ); i++ )
{
for( j = i + 1; j < str.length( ); j++ )
{
if( str[ i ] == str[ j ] )
return true;
}
}
return false;
}
2. The simplest solution is:
int CountChars( apstring source, apstring target )
{
int count = 0;
int t;
int s;
if( ContainsDuplicates( target ) )
return -1;
for( t = 0; t < target.length( ); t++ )
{
for( s = 0; s < source.length( ); s++ )
{
if( source[ s ] == target[ t ] )
count++;
}
}
return count;
}