题意:按字典序输出二个字符串相同的元素
算法:hash标记
连接:点击打开链接
#include <stdio.h>
int main ( )
{
char str[1005], ch[1005];
while ( gets ( str ) )
{
gets ( ch );
int hash[26] = { 0 }, visit[26] = { 0 }, i = 0;
while ( str[i] )
hash[str[i++]-'a']++;
i = 0;
while ( ch[i] )
visit[ch[i++]-'a']++;
for ( i = 0; i < 26; i++ )
{
int x = hash[i] > visit[i] ? visit[i] : hash[i];
while ( x-- )
printf ( "%c", i + 'a' );
}
puts ( "" );
}
return 0;
}