两层遍历,不输出重复用哈希。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
using namespace std;
#define MAX 80+5
int vis[128];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
char str1[MAX], str2[MAX];
gets(str1);
gets(str2);
for (int i = 0; i < strlen(str1); i++)
{
int j;
char c1, c2;
for (j = 0; j < strlen(str2); j++)
{
c1 = str1[i], c2 = str2[j];
if (c1 >= 'a' && c1 <= 'z')
c1 -= 32;
if (c2 >= 'a' && c2 <= 'z')
c2 -= 32;
if (c1 == c2)
break;
}
if (j == strlen(str2) && !vis[int(c1)])
{
printf("%c", c1);
vis[(int)c1] = 1;
}
}
return 0;
}