poj2629

简单题

View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;

#define maxl 1005
#define maxn 30

int f[maxn], g[maxn];
char a[maxl], b[maxl];

void make(char *st, int f[])
{
int len = strlen(st);
for (int i = 0; i < len; i++)
f[st[i] - 'a']++;
}

void work()
{
for (int i = 0; i < 26; i++)
{
int x = min(f[i], g[i]);
for (int j = 0; j < x; j++)
putchar(i + 'a');
}
putchar('\n');
}

int main()
{
//freopen("t.txt", "r", stdin);
while (gets(a))
{
gets(b);
memset(f, 0, sizeof(f));
memset(g, 0, sizeof(g));
make(a, f);
make(b, g);
work();
}
return 0;
}

posted @ 2011-10-03 17:56  金海峰  阅读(202)  评论(0编辑  收藏  举报