题意:按字典序输出二个字符串相同的元素
算法: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;
}
本文介绍了使用hash标记法按字典序输出两个字符串相同元素的算法实现步骤,并通过示例代码进行演示。
1096

被折叠的 条评论
为什么被折叠?



